chore(facade): remove most facade/async functions
This commit is contained in:
committed by
Alex Rickabaugh
parent
6baf3baedd
commit
99989f5d3f
@@ -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, FormControl, FormGroup} from '../model';
|
||||
@@ -26,6 +26,8 @@ export const formDirectiveProvider: any = {
|
||||
useExisting: forwardRef(() => NgForm)
|
||||
};
|
||||
|
||||
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.
|
||||
@@ -117,7 +119,7 @@ export class NgForm extends ControlContainer implements Form {
|
||||
get controls(): {[key: string]: AbstractControl} { return this.form.controls; }
|
||||
|
||||
addControl(dir: NgModel): void {
|
||||
PromiseWrapper.scheduleMicrotask(() => {
|
||||
resolvedPromise.then(() => {
|
||||
const container = this._findContainer(dir.path);
|
||||
dir._control = <FormControl>container.registerControl(dir.name, dir.control);
|
||||
setUpControl(dir.control, dir);
|
||||
@@ -128,7 +130,7 @@ export class NgForm extends ControlContainer implements Form {
|
||||
getControl(dir: NgModel): FormControl { return <FormControl>this.form.find(dir.path); }
|
||||
|
||||
removeControl(dir: NgModel): void {
|
||||
PromiseWrapper.scheduleMicrotask(() => {
|
||||
resolvedPromise.then(() => {
|
||||
var container = this._findContainer(dir.path);
|
||||
if (isPresent(container)) {
|
||||
container.removeControl(dir.name);
|
||||
@@ -137,7 +139,7 @@ export class NgForm extends ControlContainer implements Form {
|
||||
}
|
||||
|
||||
addFormGroup(dir: NgModelGroup): void {
|
||||
PromiseWrapper.scheduleMicrotask(() => {
|
||||
resolvedPromise.then(() => {
|
||||
var container = this._findContainer(dir.path);
|
||||
var group = new FormGroup({});
|
||||
setUpFormContainer(group, dir);
|
||||
@@ -147,7 +149,7 @@ export class NgForm extends ControlContainer implements Form {
|
||||
}
|
||||
|
||||
removeFormGroup(dir: NgModelGroup): void {
|
||||
PromiseWrapper.scheduleMicrotask(() => {
|
||||
resolvedPromise.then(() => {
|
||||
var container = this._findContainer(dir.path);
|
||||
if (isPresent(container)) {
|
||||
container.removeControl(dir.name);
|
||||
@@ -158,7 +160,7 @@ export class NgForm extends ControlContainer implements Form {
|
||||
getFormGroup(dir: NgModelGroup): FormGroup { return <FormGroup>this.form.find(dir.path); }
|
||||
|
||||
updateModel(dir: NgControl, value: any): void {
|
||||
PromiseWrapper.scheduleMicrotask(() => {
|
||||
resolvedPromise.then(() => {
|
||||
var ctrl = <FormControl>this.form.find(dir.path);
|
||||
ctrl.updateValue(value);
|
||||
});
|
||||
@@ -168,7 +170,7 @@ export class NgForm extends ControlContainer implements Form {
|
||||
|
||||
onSubmit(): boolean {
|
||||
this._submitted = true;
|
||||
ObservableWrapper.callEmit(this.ngSubmit, null);
|
||||
this.ngSubmit.emit(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import {Directive, Host, Inject, Input, OnChanges, OnDestroy, Optional, Output, Self, SimpleChanges, forwardRef} from '@angular/core';
|
||||
|
||||
import {EventEmitter, ObservableWrapper, PromiseWrapper} from '../facade/async';
|
||||
import {EventEmitter} from '../facade/async';
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
import {FormControl} from '../model';
|
||||
import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators';
|
||||
@@ -28,6 +28,8 @@ export const formControlBinding: any = {
|
||||
useExisting: forwardRef(() => NgModel)
|
||||
};
|
||||
|
||||
const resolvedPromise = Promise.resolve(null);
|
||||
|
||||
/**
|
||||
* Binds a domain model to a form control.
|
||||
*
|
||||
@@ -105,7 +107,7 @@ export class NgModel extends NgControl implements OnChanges,
|
||||
|
||||
viewToModelUpdate(newValue: any): void {
|
||||
this.viewModel = newValue;
|
||||
ObservableWrapper.callEmit(this.update, newValue);
|
||||
this.update.emit(newValue);
|
||||
}
|
||||
|
||||
private _setUpControl(): void {
|
||||
@@ -149,7 +151,7 @@ export class NgModel extends NgControl implements OnChanges,
|
||||
}
|
||||
|
||||
private _updateValue(value: any): void {
|
||||
PromiseWrapper.scheduleMicrotask(
|
||||
resolvedPromise.then(
|
||||
() => { this.control.updateValue(value, {emitViewToModelChange: false}); });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import {Directive, Inject, Input, OnChanges, Optional, Output, Self, SimpleChanges, forwardRef} from '@angular/core';
|
||||
|
||||
import {EventEmitter, ObservableWrapper} from '../../facade/async';
|
||||
import {EventEmitter} from '../../facade/async';
|
||||
import {StringMapWrapper} from '../../facade/collection';
|
||||
import {FormControl} from '../../model';
|
||||
import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../../validators';
|
||||
@@ -110,7 +110,7 @@ export class FormControlDirective 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 {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import {Directive, Host, Inject, Input, OnChanges, OnDestroy, Optional, Output, Self, SimpleChanges, SkipSelf, forwardRef} from '@angular/core';
|
||||
|
||||
import {EventEmitter, ObservableWrapper} from '../../facade/async';
|
||||
import {EventEmitter} from '../../facade/async';
|
||||
import {FormControl} from '../../model';
|
||||
import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../../validators';
|
||||
import {AbstractFormGroupDirective} from '../abstract_form_group_directive';
|
||||
@@ -134,7 +134,7 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {
|
||||
|
||||
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); }
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import {Directive, Inject, Input, OnChanges, Optional, Output, 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';
|
||||
@@ -182,7 +182,7 @@ export class FormGroupDirective extends ControlContainer implements Form,
|
||||
|
||||
onSubmit(): boolean {
|
||||
this._submitted = true;
|
||||
ObservableWrapper.callEmit(this.ngSubmit, null);
|
||||
this.ngSubmit.emit(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,14 +6,17 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {PromiseObservable} from 'rxjs/observable/PromiseObservable';
|
||||
|
||||
import {composeAsyncValidators, composeValidators} from './directives/shared';
|
||||
import {AsyncValidatorFn, ValidatorFn} from './directives/validators';
|
||||
import {EventEmitter, Observable, ObservableWrapper} from './facade/async';
|
||||
import {EventEmitter, Observable} from './facade/async';
|
||||
import {ListWrapper, StringMapWrapper} from './facade/collection';
|
||||
import {BaseException} from './facade/exceptions';
|
||||
import {isBlank, isPresent, isPromise, normalizeBool} from './facade/lang';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Indicates that a FormControl is valid, i.e. that no errors exist in the input value.
|
||||
*/
|
||||
@@ -55,7 +58,7 @@ function _find(control: AbstractControl, path: Array<string|number>| string, del
|
||||
}
|
||||
|
||||
function toObservable(r: any): Observable<any> {
|
||||
return isPromise(r) ? ObservableWrapper.fromPromise(r) : r;
|
||||
return isPromise(r) ? PromiseObservable.create(r) : r;
|
||||
}
|
||||
|
||||
function coerceToValidator(validator: ValidatorFn | ValidatorFn[]): ValidatorFn {
|
||||
@@ -193,8 +196,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) {
|
||||
@@ -211,14 +214,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,7 +290,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)) {
|
||||
|
||||
@@ -7,13 +7,14 @@
|
||||
*/
|
||||
|
||||
import {OpaqueToken} from '@angular/core';
|
||||
import {toPromise} from 'rxjs/operator/toPromise';
|
||||
|
||||
import {AsyncValidatorFn, ValidatorFn} from './directives/validators';
|
||||
import {ObservableWrapper} from './facade/async';
|
||||
import {StringMapWrapper} from './facade/collection';
|
||||
import {isBlank, isPresent, isPromise, isString} from './facade/lang';
|
||||
import {PromiseWrapper} from './facade/promise';
|
||||
import {AbstractControl} from './model';
|
||||
|
||||
|
||||
/**
|
||||
* Providers for validators to be used for {@link FormControl}s in a form.
|
||||
*
|
||||
@@ -127,13 +128,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[] {
|
||||
|
||||
Reference in New Issue
Block a user