fix(core): unify the signature between ngZone and noopZone (#37581)
Now we have two implementations of Zone in Angular, one is NgZone, the other is NoopZone. They should have the same signatures, includes 1. properties 2. methods In this PR, unify the signatures of the two implementations, and remove the unnecessary cast. PR Close #37581
This commit is contained in:
parent
e79b6c31f9
commit
b142283ba2
|
@ -177,7 +177,7 @@ export class NgZone {
|
||||||
* If a synchronous error happens it will be rethrown and not reported via `onError`.
|
* If a synchronous error happens it will be rethrown and not reported via `onError`.
|
||||||
*/
|
*/
|
||||||
run<T>(fn: (...args: any[]) => T, applyThis?: any, applyArgs?: any[]): T {
|
run<T>(fn: (...args: any[]) => T, applyThis?: any, applyArgs?: any[]): T {
|
||||||
return (this as any as NgZonePrivate)._inner.run(fn, applyThis, applyArgs) as T;
|
return (this as any as NgZonePrivate)._inner.run(fn, applyThis, applyArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -196,7 +196,7 @@ export class NgZone {
|
||||||
const zone = (this as any as NgZonePrivate)._inner;
|
const zone = (this as any as NgZonePrivate)._inner;
|
||||||
const task = zone.scheduleEventTask('NgZoneEvent: ' + name, fn, EMPTY_PAYLOAD, noop, noop);
|
const task = zone.scheduleEventTask('NgZoneEvent: ' + name, fn, EMPTY_PAYLOAD, noop, noop);
|
||||||
try {
|
try {
|
||||||
return zone.runTask(task, applyThis, applyArgs) as T;
|
return zone.runTask(task, applyThis, applyArgs);
|
||||||
} finally {
|
} finally {
|
||||||
zone.cancelTask(task);
|
zone.cancelTask(task);
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ export class NgZone {
|
||||||
* rethrown.
|
* rethrown.
|
||||||
*/
|
*/
|
||||||
runGuarded<T>(fn: (...args: any[]) => T, applyThis?: any, applyArgs?: any[]): T {
|
runGuarded<T>(fn: (...args: any[]) => T, applyThis?: any, applyArgs?: any[]): T {
|
||||||
return (this as any as NgZonePrivate)._inner.runGuarded(fn, applyThis, applyArgs) as T;
|
return (this as any as NgZonePrivate)._inner.runGuarded(fn, applyThis, applyArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -224,7 +224,7 @@ export class NgZone {
|
||||||
* Use {@link #run} to reenter the Angular zone and do work that updates the application model.
|
* Use {@link #run} to reenter the Angular zone and do work that updates the application model.
|
||||||
*/
|
*/
|
||||||
runOutsideAngular<T>(fn: (...args: any[]) => T): T {
|
runOutsideAngular<T>(fn: (...args: any[]) => T): T {
|
||||||
return (this as any as NgZonePrivate)._outer.run(fn) as T;
|
return (this as any as NgZonePrivate)._outer.run(fn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,19 +388,19 @@ export class NoopNgZone implements NgZone {
|
||||||
readonly onStable: EventEmitter<any> = new EventEmitter();
|
readonly onStable: EventEmitter<any> = new EventEmitter();
|
||||||
readonly onError: EventEmitter<any> = new EventEmitter();
|
readonly onError: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
run(fn: (...args: any[]) => any, applyThis?: any, applyArgs?: any): any {
|
run<T>(fn: (...args: any[]) => T, applyThis?: any, applyArgs?: any): T {
|
||||||
return fn.apply(applyThis, applyArgs);
|
return fn.apply(applyThis, applyArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
runGuarded(fn: (...args: any[]) => any, applyThis?: any, applyArgs?: any): any {
|
runGuarded<T>(fn: (...args: any[]) => any, applyThis?: any, applyArgs?: any): T {
|
||||||
return fn.apply(applyThis, applyArgs);
|
return fn.apply(applyThis, applyArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
runOutsideAngular(fn: (...args: any[]) => any): any {
|
runOutsideAngular<T>(fn: (...args: any[]) => T): T {
|
||||||
return fn();
|
return fn();
|
||||||
}
|
}
|
||||||
|
|
||||||
runTask(fn: (...args: any[]) => any, applyThis?: any, applyArgs?: any, name?: string): any {
|
runTask<T>(fn: (...args: any[]) => T, applyThis?: any, applyArgs?: any, name?: string): T {
|
||||||
return fn.apply(applyThis, applyArgs);
|
return fn.apply(applyThis, applyArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,9 +223,9 @@ interface Zone {
|
||||||
* @param task to run
|
* @param task to run
|
||||||
* @param applyThis
|
* @param applyThis
|
||||||
* @param applyArgs
|
* @param applyArgs
|
||||||
* @returns {*}
|
* @returns {any} Value from the `task.callback` function.
|
||||||
*/
|
*/
|
||||||
runTask(task: Task, applyThis?: any, applyArgs?: any): any;
|
runTask<T>(task: Task, applyThis?: any, applyArgs?: any): T;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedule a MicroTask.
|
* Schedule a MicroTask.
|
||||||
|
|
Loading…
Reference in New Issue