refactor: misc cleanup (#9369)

This commit is contained in:
Victor Berchet 2016-06-20 10:55:29 -07:00 committed by GitHub
parent 1b28cf71f5
commit ca42b49fa2
7 changed files with 11 additions and 74 deletions

View File

@ -1,11 +1,8 @@
import {EventEmitter, Observable, ObservableWrapper} from '../facade/async'; import {EventEmitter, Observable, ObservableWrapper} from '../facade/async';
import {ListWrapper, StringMapWrapper} from '../facade/collection'; import {ListWrapper, StringMapWrapper} from '../facade/collection';
import {isBlank, isPresent, normalizeBool} from '../facade/lang'; import {isBlank, isPresent, isPromise, normalizeBool} from '../facade/lang';
import {PromiseWrapper} from '../facade/promise';
import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; import {AsyncValidatorFn, ValidatorFn} from './directives/validators';
/** /**
* Indicates that a Control is valid, i.e. that no errors exist in the input value. * Indicates that a Control is valid, i.e. that no errors exist in the input value.
*/ */
@ -47,7 +44,7 @@ function _find(control: AbstractControl, path: Array<string|number>| string) {
} }
function toObservable(r: any): Observable<any> { function toObservable(r: any): Observable<any> {
return PromiseWrapper.isPromise(r) ? ObservableWrapper.fromPromise(r) : r; return isPromise(r) ? ObservableWrapper.fromPromise(r) : r;
} }
/** /**

View File

@ -1,14 +1,11 @@
import {OpaqueToken} from '@angular/core'; import {OpaqueToken} from '@angular/core';
import {ObservableWrapper} from '../facade/async'; import {ObservableWrapper} from '../facade/async';
import {StringMapWrapper} from '../facade/collection'; import {StringMapWrapper} from '../facade/collection';
import {isBlank, isPresent, isString} from '../facade/lang'; import {isBlank, isPresent, isPromise, isString} from '../facade/lang';
import {PromiseWrapper} from '../facade/promise'; import {PromiseWrapper} from '../facade/promise';
import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; import {AsyncValidatorFn, ValidatorFn} from './directives/validators';
import * as modelModule from './model'; import * as modelModule from './model';
/** /**
* Providers for validators to be used for {@link Control}s in a form. * Providers for validators to be used for {@link Control}s in a form.
* *
@ -128,8 +125,8 @@ export class Validators {
} }
} }
function _convertToPromise(obj: any): any { function _convertToPromise(obj: any): Promise<any> {
return PromiseWrapper.isPromise(obj) ? obj : ObservableWrapper.toPromise(obj); return isPromise(obj) ? obj : ObservableWrapper.toPromise(obj);
} }
function _executeValidators( function _executeValidators(

View File

@ -43,7 +43,7 @@ export class ObservableWrapper {
/** /**
* @deprecated - use callEmit() instead * @deprecated - use callEmit() instead
*/ */
static callNext(emitter: EventEmitter<any>, value: any) { emitter.next(value); } static callNext(emitter: EventEmitter<any>, value: any) { emitter.emit(value); }
static callEmit(emitter: EventEmitter<any>, value: any) { emitter.emit(value); } static callEmit(emitter: EventEmitter<any>, value: any) { emitter.emit(value); }

View File

@ -1,49 +0,0 @@
"use strict";
var PromiseCompleter = (function () {
function PromiseCompleter() {
var _this = this;
this.promise = new Promise(function (res, rej) {
_this.resolve = res;
_this.reject = rej;
});
}
return PromiseCompleter;
}());
exports.PromiseCompleter = PromiseCompleter;
var PromiseWrapper = (function () {
function PromiseWrapper() {
}
PromiseWrapper.resolve = function (obj) { return Promise.resolve(obj); };
PromiseWrapper.reject = function (obj, _) { return Promise.reject(obj); };
// Note: We can't rename this method into `catch`, as this is not a valid
// method name in Dart.
PromiseWrapper.catchError = function (promise, onError) {
return promise.catch(onError);
};
PromiseWrapper.all = function (promises) {
if (promises.length == 0)
return Promise.resolve([]);
return Promise.all(promises);
};
PromiseWrapper.then = function (promise, success, rejection) {
return promise.then(success, rejection);
};
PromiseWrapper.wrap = function (computation) {
return new Promise(function (res, rej) {
try {
res(computation());
}
catch (e) {
rej(e);
}
});
};
PromiseWrapper.scheduleMicrotask = function (computation) {
PromiseWrapper.then(PromiseWrapper.resolve(null), computation, function (_) { });
};
PromiseWrapper.isPromise = function (obj) { return obj instanceof Promise; };
PromiseWrapper.completer = function () { return new PromiseCompleter(); };
return PromiseWrapper;
}());
exports.PromiseWrapper = PromiseWrapper;
//# sourceMappingURL=promise.js.map

View File

@ -49,7 +49,5 @@ export class PromiseWrapper {
PromiseWrapper.then(PromiseWrapper.resolve(null), computation, (_) => {}); PromiseWrapper.then(PromiseWrapper.resolve(null), computation, (_) => {});
} }
static isPromise(obj: any): boolean { return obj instanceof Promise; }
static completer<T>(): PromiseCompleter<T> { return new PromiseCompleter<T>(); } static completer<T>(): PromiseCompleter<T> { return new PromiseCompleter<T>(); }
} }

View File

@ -2,10 +2,7 @@ import {composeAsyncValidators, composeValidators} from './directives/shared';
import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; import {AsyncValidatorFn, ValidatorFn} from './directives/validators';
import {EventEmitter, Observable, ObservableWrapper} from './facade/async'; import {EventEmitter, Observable, ObservableWrapper} from './facade/async';
import {ListWrapper, StringMapWrapper} from './facade/collection'; import {ListWrapper, StringMapWrapper} from './facade/collection';
import {isBlank, isPresent, normalizeBool} from './facade/lang'; import {isBlank, isPresent, isPromise, normalizeBool} from './facade/lang';
import {PromiseWrapper} from './facade/promise';
/** /**
* Indicates that a FormControl is valid, i.e. that no errors exist in the input value. * Indicates that a FormControl is valid, i.e. that no errors exist in the input value.
@ -48,7 +45,7 @@ function _find(control: AbstractControl, path: Array<string|number>| string) {
} }
function toObservable(r: any): Observable<any> { function toObservable(r: any): Observable<any> {
return PromiseWrapper.isPromise(r) ? ObservableWrapper.fromPromise(r) : r; return isPromise(r) ? ObservableWrapper.fromPromise(r) : r;
} }
function coerceToValidator(validator: ValidatorFn | ValidatorFn[]): ValidatorFn { function coerceToValidator(validator: ValidatorFn | ValidatorFn[]): ValidatorFn {

View File

@ -1,14 +1,11 @@
import {OpaqueToken} from '@angular/core'; import {OpaqueToken} from '@angular/core';
import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; import {AsyncValidatorFn, ValidatorFn} from './directives/validators';
import {ObservableWrapper} from './facade/async'; import {ObservableWrapper} from './facade/async';
import {StringMapWrapper} from './facade/collection'; import {StringMapWrapper} from './facade/collection';
import {isBlank, isPresent, isString} from './facade/lang'; import {isBlank, isPresent, isPromise, isString} from './facade/lang';
import {PromiseWrapper} from './facade/promise'; import {PromiseWrapper} from './facade/promise';
import * as modelModule from './model'; import * as modelModule from './model';
/** /**
* Providers for validators to be used for {@link FormControl}s in a form. * Providers for validators to be used for {@link FormControl}s in a form.
* *
@ -128,8 +125,8 @@ export class Validators {
} }
} }
function _convertToPromise(obj: any): any { function _convertToPromise(obj: any): Promise<any> {
return PromiseWrapper.isPromise(obj) ? obj : ObservableWrapper.toPromise(obj); return isPromise(obj) ? obj : ObservableWrapper.toPromise(obj);
} }
function _executeValidators( function _executeValidators(