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

@ -6,16 +6,19 @@
* found in the LICENSE file at https://angular.io/license
*/
import {PromiseCompleter} from '../src/facade/promise';
/**
* Injectable completer that allows signaling completion of an asynchronous test. Used internally.
*/
export class AsyncTestCompleter {
private _completer = new PromiseCompleter<any>();
done(value?: any) { this._completer.resolve(value); }
private _resolve: (result: any) => void;
private _reject: (err: any) => void;
private _promise: Promise<any> = new Promise((res, rej) => {
this._resolve = res;
this._reject = rej;
});
done(value?: any) { this._resolve(value); }
fail(error?: any, stackTrace?: string) { this._completer.reject(error, stackTrace); }
fail(error?: any, stackTrace?: string) { this._reject(error); }
get promise(): Promise<any> { return this._completer.promise; }
get promise(): Promise<any> { return this._promise; }
}

View File

@ -7,7 +7,6 @@
*/
import {AnimationEntryMetadata, ChangeDetectorRef, ComponentFactory, ComponentRef, ComponentResolver, DebugElement, ElementRef, Injectable, Injector, NgZone, NgZoneError, OpaqueToken, ViewMetadata, getDebugNode} from '../index';
import {ObservableWrapper, PromiseCompleter, PromiseWrapper} from '../src/facade/async';
import {BaseException} from '../src/facade/exceptions';
import {scheduleMicroTask} from '../src/facade/lang';
@ -58,7 +57,8 @@ export class ComponentFixture<T> {
private _autoDetect: boolean;
private _isStable: boolean = true;
private _completer: PromiseCompleter<any> = null;
private _resolve: (result: any) => void;
private _promise: Promise<any> = null;
private _onUnstableSubscription: any /** TODO #9100 */ = null;
private _onStableSubscription: any /** TODO #9100 */ = null;
private _onMicrotaskEmptySubscription: any /** TODO #9100 */ = null;
@ -76,35 +76,39 @@ export class ComponentFixture<T> {
if (ngZone != null) {
this._onUnstableSubscription =
ObservableWrapper.subscribe(ngZone.onUnstable, (_) => { this._isStable = false; });
this._onMicrotaskEmptySubscription =
ObservableWrapper.subscribe(ngZone.onMicrotaskEmpty, (_) => {
if (this._autoDetect) {
// Do a change detection run with checkNoChanges set to true to check
// there are no changes on the second run.
this.detectChanges(true);
}
});
this._onStableSubscription = ObservableWrapper.subscribe(ngZone.onStable, (_) => {
this._isStable = true;
// Check whether there is a pending whenStable() completer to resolve.
if (this._completer !== null) {
// If so check whether there are no pending macrotasks before resolving.
// Do this check in the next tick so that ngZone gets a chance to update the state of
// pending macrotasks.
scheduleMicroTask(() => {
if (!this.ngZone.hasPendingMacrotasks) {
if (this._completer !== null) {
this._completer.resolve(true);
this._completer = null;
ngZone.onUnstable.subscribe({next: () => { this._isStable = false; }});
this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({
next: () => {
if (this._autoDetect) {
// Do a change detection run with checkNoChanges set to true to check
// there are no changes on the second run.
this.detectChanges(true);
}
}
});
this._onStableSubscription = ngZone.onStable.subscribe({
next: () => {
this._isStable = true;
// Check whether there is a pending whenStable() completer to resolve.
if (this._promise !== null) {
// If so check whether there are no pending macrotasks before resolving.
// Do this check in the next tick so that ngZone gets a chance to update the state of
// pending macrotasks.
scheduleMicroTask(() => {
if (!this.ngZone.hasPendingMacrotasks) {
if (this._promise !== null) {
this._resolve(true);
this._resolve = null;
this._promise = null;
}
}
}
});
});
}
}
});
this._onErrorSubscription = ObservableWrapper.subscribe(
ngZone.onError, (error: NgZoneError) => { throw error.error; });
this._onErrorSubscription =
ngZone.onError.subscribe({next: (error: NgZoneError) => { throw error.error; }});
}
}
@ -161,12 +165,12 @@ export class ComponentFixture<T> {
*/
whenStable(): Promise<any> {
if (this.isStable()) {
return PromiseWrapper.resolve(false);
} else if (this._completer !== null) {
return this._completer.promise;
return Promise.resolve(false);
} else if (this._promise !== null) {
return this._promise;
} else {
this._completer = new PromiseCompleter<any>();
return this._completer.promise;
this._promise = new Promise(res => { this._resolve = res; });
return this._promise;
}
}
@ -176,19 +180,19 @@ export class ComponentFixture<T> {
destroy(): void {
this.componentRef.destroy();
if (this._onUnstableSubscription != null) {
ObservableWrapper.dispose(this._onUnstableSubscription);
this._onUnstableSubscription.unsubscribe();
this._onUnstableSubscription = null;
}
if (this._onStableSubscription != null) {
ObservableWrapper.dispose(this._onStableSubscription);
this._onStableSubscription.unsubscribe();
this._onStableSubscription = null;
}
if (this._onMicrotaskEmptySubscription != null) {
ObservableWrapper.dispose(this._onMicrotaskEmptySubscription);
this._onMicrotaskEmptySubscription.unsubscribe();
this._onMicrotaskEmptySubscription = null;
}
if (this._onErrorSubscription != null) {
ObservableWrapper.dispose(this._onErrorSubscription);
this._onErrorSubscription.unsubscribe();
this._onErrorSubscription = null;
}
}

View File

@ -7,7 +7,7 @@
*/
import {Injectable, NgZone} from '../index';
import {EventEmitter, ObservableWrapper} from '../src/facade/async';
import {EventEmitter} from '../src/facade/async';
/**
* A mock implementation of {@link NgZone}.
@ -24,5 +24,5 @@ export class MockNgZone extends NgZone {
runOutsideAngular(fn: Function): any { return fn(); }
simulateZoneExit(): void { ObservableWrapper.callNext(this.onStable, null); }
simulateZoneExit(): void { this.onStable.emit(null); }
}

View File

@ -7,7 +7,6 @@
*/
import {AnimationEntryMetadata, Compiler, ComponentFactory, Injectable, Injector, NgZone, OpaqueToken, ViewMetadata} from '../index';
import {PromiseWrapper} from '../src/facade/async';
import {ConcreteType, Type, isPresent} from '../src/facade/lang';
import {ComponentFixture} from './component_fixture';
@ -119,9 +118,9 @@ export class TestComponentBuilder {
createFakeAsync<T>(rootComponentType: ConcreteType<T>): ComponentFixture<T> {
let result: any /** TODO #9100 */;
let error: any /** TODO #9100 */;
PromiseWrapper.then(
this.createAsync(rootComponentType), (_result) => { result = _result; },
(_error) => { error = _error; });
this.createAsync(rootComponentType)
.then((_result) => { result = _result; }, (_error) => { error = _error; });
tick();
if (isPresent(error)) {
throw error;