chore(facade): remove most facade/async functions
This commit is contained in:

committed by
Alex Rickabaugh

parent
6baf3baedd
commit
99989f5d3f
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user