chore(facade): remove most facade/async functions

This commit is contained in:
Jason Choi
2016-08-02 15:53:34 -07:00
committed by Alex Rickabaugh
parent 6baf3baedd
commit 99989f5d3f
184 changed files with 1609 additions and 1698 deletions

View File

@ -8,7 +8,7 @@
import {Directive, Host, Inject, OnChanges, OnDestroy, Optional, Self, SimpleChanges, SkipSelf, forwardRef} from '@angular/core';
import {EventEmitter, ObservableWrapper} from '../../facade/async';
import {EventEmitter} from '../../facade/async';
import {Control} from '../model';
import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators';
@ -122,7 +122,7 @@ export class NgControlName extends NgControl implements OnChanges,
viewToModelUpdate(newValue: any): void {
this.viewModel = newValue;
ObservableWrapper.callEmit(this.update, newValue);
this.update.emit(newValue);
}
get path(): string[] { return controlPath(this.name, this._parent); }

View File

@ -8,7 +8,7 @@
import {Directive, Inject, Optional, Self, forwardRef} from '@angular/core';
import {EventEmitter, ObservableWrapper, PromiseWrapper} from '../../facade/async';
import {EventEmitter} from '../../facade/async';
import {ListWrapper} from '../../facade/collection';
import {isPresent} from '../../facade/lang';
import {AbstractControl, Control, ControlGroup} from '../model';
@ -27,6 +27,8 @@ export const formDirectiveProvider: any = {
let _formWarningDisplayed: boolean = false;
const resolvedPromise = Promise.resolve(null);
/**
* If `NgForm` is bound in a component, `<form>` elements in that component will be
* upgraded to use the Angular form system.
@ -136,7 +138,7 @@ export class NgForm extends ControlContainer implements Form {
get controls(): {[key: string]: AbstractControl} { return this.form.controls; }
addControl(dir: NgControl): void {
PromiseWrapper.scheduleMicrotask(() => {
resolvedPromise.then(() => {
var container = this._findContainer(dir.path);
var ctrl = new Control();
setUpControl(ctrl, dir);
@ -148,7 +150,7 @@ export class NgForm extends ControlContainer implements Form {
getControl(dir: NgControl): Control { return <Control>this.form.find(dir.path); }
removeControl(dir: NgControl): void {
PromiseWrapper.scheduleMicrotask(() => {
resolvedPromise.then(() => {
var container = this._findContainer(dir.path);
if (isPresent(container)) {
container.removeControl(dir.name);
@ -157,7 +159,7 @@ export class NgForm extends ControlContainer implements Form {
}
addControlGroup(dir: NgControlGroup): void {
PromiseWrapper.scheduleMicrotask(() => {
resolvedPromise.then(() => {
var container = this._findContainer(dir.path);
var group = new ControlGroup({});
setUpControlGroup(group, dir);
@ -167,7 +169,7 @@ export class NgForm extends ControlContainer implements Form {
}
removeControlGroup(dir: NgControlGroup): void {
PromiseWrapper.scheduleMicrotask(() => {
resolvedPromise.then(() => {
var container = this._findContainer(dir.path);
if (isPresent(container)) {
container.removeControl(dir.name);
@ -180,7 +182,7 @@ export class NgForm extends ControlContainer implements Form {
}
updateModel(dir: NgControl, value: any): void {
PromiseWrapper.scheduleMicrotask(() => {
resolvedPromise.then(() => {
var ctrl = <Control>this.form.find(dir.path);
ctrl.updateValue(value);
});
@ -188,7 +190,7 @@ export class NgForm extends ControlContainer implements Form {
onSubmit(): boolean {
this._submitted = true;
ObservableWrapper.callEmit(this.ngSubmit, null);
this.ngSubmit.emit(null);
return false;
}

View File

@ -8,7 +8,7 @@
import {Directive, Inject, OnChanges, Optional, Self, SimpleChanges, forwardRef} from '@angular/core';
import {EventEmitter, ObservableWrapper} from '../../facade/async';
import {EventEmitter} from '../../facade/async';
import {StringMapWrapper} from '../../facade/collection';
import {Control} from '../model';
import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators';
@ -118,7 +118,7 @@ export class NgFormControl extends NgControl implements OnChanges {
viewToModelUpdate(newValue: any): void {
this.viewModel = newValue;
ObservableWrapper.callEmit(this.update, newValue);
this.update.emit(newValue);
}
private _isControlChanged(changes: {[key: string]: any}): boolean {

View File

@ -8,7 +8,7 @@
import {Directive, Inject, OnChanges, Optional, Self, SimpleChanges, forwardRef} from '@angular/core';
import {EventEmitter, ObservableWrapper} from '../../facade/async';
import {EventEmitter} from '../../facade/async';
import {ListWrapper, StringMapWrapper} from '../../facade/collection';
import {BaseException} from '../../facade/exceptions';
import {isBlank} from '../../facade/lang';
@ -191,7 +191,7 @@ export class NgFormModel extends ControlContainer implements Form,
onSubmit(): boolean {
this._submitted = true;
ObservableWrapper.callEmit(this.ngSubmit, null);
this.ngSubmit.emit(null);
return false;
}

View File

@ -8,7 +8,7 @@
import {Directive, Inject, OnChanges, Optional, Self, SimpleChanges, forwardRef} from '@angular/core';
import {EventEmitter, ObservableWrapper} from '../../facade/async';
import {EventEmitter} from '../../facade/async';
import {Control} from '../model';
import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators';
@ -94,6 +94,6 @@ export class NgModel extends NgControl implements OnChanges {
viewToModelUpdate(newValue: any): void {
this.viewModel = newValue;
ObservableWrapper.callEmit(this.update, newValue);
this.update.emit(newValue);
}
}

View File

@ -6,11 +6,15 @@
* found in the LICENSE file at https://angular.io/license
*/
import {EventEmitter, Observable, ObservableWrapper} from '../facade/async';
import {PromiseObservable} from 'rxjs/observable/PromiseObservable';
import {EventEmitter, Observable} from '../facade/async';
import {ListWrapper, StringMapWrapper} from '../facade/collection';
import {isBlank, isPresent, isPromise, normalizeBool} from '../facade/lang';
import {AsyncValidatorFn, ValidatorFn} from './directives/validators';
/**
* Indicates that a Control is valid, i.e. that no errors exist in the input value.
*/
@ -52,7 +56,7 @@ function _find(control: AbstractControl, path: Array<string|number>| string) {
}
function toObservable(r: any): Observable<any> {
return isPromise(r) ? ObservableWrapper.fromPromise(r) : r;
return isPromise(r) ? PromiseObservable.create(r) : r;
}
/**
@ -135,8 +139,8 @@ export abstract class AbstractControl {
}
if (emitEvent) {
ObservableWrapper.callEmit(this._valueChanges, this._value);
ObservableWrapper.callEmit(this._statusChanges, this._status);
this._valueChanges.emit(this._value);
this._statusChanges.emit(this._status);
}
if (isPresent(this._parent) && !onlySelf) {
@ -153,14 +157,14 @@ export abstract class AbstractControl {
this._status = PENDING;
this._cancelExistingSubscription();
var obs = toObservable(this.asyncValidator(this));
this._asyncValidationSubscription = ObservableWrapper.subscribe(
obs, (res: {[key: string]: any}) => this.setErrors(res, {emitEvent: emitEvent}));
this._asyncValidationSubscription = obs.subscribe(
{next: (res: {[key: string]: any}) => this.setErrors(res, {emitEvent: emitEvent})});
}
}
private _cancelExistingSubscription(): void {
if (isPresent(this._asyncValidationSubscription)) {
ObservableWrapper.dispose(this._asyncValidationSubscription);
this._asyncValidationSubscription.unsubscribe();
}
}
@ -194,7 +198,7 @@ export abstract class AbstractControl {
this._status = this._calculateStatus();
if (emitEvent) {
ObservableWrapper.callEmit(this._statusChanges, this._status);
this._statusChanges.emit(this._status);
}
if (isPresent(this._parent)) {

View File

@ -7,13 +7,15 @@
*/
import {OpaqueToken} from '@angular/core';
import {ObservableWrapper} from '../facade/async';
import {toPromise} from 'rxjs/operator/toPromise';
import {StringMapWrapper} from '../facade/collection';
import {isBlank, isPresent, isPromise, isString} from '../facade/lang';
import {PromiseWrapper} from '../facade/promise';
import {AsyncValidatorFn, ValidatorFn} from './directives/validators';
import {AbstractControl} from './model';
/**
* Providers for validators to be used for {@link Control}s in a form.
*
@ -127,13 +129,13 @@ export class Validators {
return function(control: AbstractControl) {
let promises = _executeAsyncValidators(control, presentValidators).map(_convertToPromise);
return PromiseWrapper.all(promises).then(_mergeErrors);
return Promise.all(promises).then(_mergeErrors);
};
}
}
function _convertToPromise(obj: any): Promise<any> {
return isPromise(obj) ? obj : ObservableWrapper.toPromise(obj);
return isPromise(obj) ? obj : toPromise.call(obj);
}
function _executeValidators(control: AbstractControl, validators: ValidatorFn[]): any[] {

View File

@ -8,8 +8,6 @@
import {EventEmitter, Injectable} from '@angular/core';
import {ObservableWrapper} from '../facade/async';
import {LocationStrategy} from './location_strategy';
@ -69,10 +67,8 @@ export class Location {
this._platformStrategy = platformStrategy;
var browserBaseHref = this._platformStrategy.getBaseHref();
this._baseHref = Location.stripTrailingSlash(_stripIndexHtml(browserBaseHref));
this._platformStrategy.onPopState((ev) => {
ObservableWrapper.callEmit(
this._subject, {'url': this.path(true), 'pop': true, 'type': ev.type});
});
this._platformStrategy.onPopState(
(ev) => { this._subject.emit({'url': this.path(true), 'pop': true, 'type': ev.type}); });
}
/**
@ -145,7 +141,7 @@ export class Location {
subscribe(
onNext: (value: any) => void, onThrow: (exception: any) => void = null,
onReturn: () => void = null): Object {
return ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn);
return this._subject.subscribe({next: onNext, error: onThrow, complete: onReturn});
}
/**

View File

@ -7,7 +7,7 @@
*/
import {ChangeDetectorRef, OnDestroy, Pipe, WrappedValue} from '@angular/core';
import {EventEmitter, Observable, ObservableWrapper} from '../facade/async';
import {EventEmitter, Observable} from '../facade/async';
import {isBlank, isPresent, isPromise} from '../facade/lang';
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
@ -19,12 +19,12 @@ interface SubscriptionStrategy {
class ObservableStrategy implements SubscriptionStrategy {
createSubscription(async: any, updateLatestValue: any): any {
return ObservableWrapper.subscribe(async, updateLatestValue, e => { throw e; });
return async.subscribe({next: updateLatestValue, error: (e: any) => { throw e; }});
}
dispose(subscription: any): void { ObservableWrapper.dispose(subscription); }
dispose(subscription: any): void { subscription.unsubscribe(); }
onDestroy(subscription: any): void { ObservableWrapper.dispose(subscription); }
onDestroy(subscription: any): void { subscription.unsubscribe(); }
}
class PromiseStrategy implements SubscriptionStrategy {
@ -125,7 +125,7 @@ export class AsyncPipe implements OnDestroy {
_selectStrategy(obj: Observable<any>|Promise<any>|EventEmitter<any>): any {
if (isPromise(obj)) {
return _promiseStrategy;
} else if (ObservableWrapper.isObservable(obj)) {
} else if ((<any>obj).subscribe) {
return _observableStrategy;
} else {
throw new InvalidPipeArgumentException(AsyncPipe, obj);