diff --git a/lib/zone.ts b/lib/zone.ts index 4de4e077d..845cd0332 100644 --- a/lib/zone.ts +++ b/lib/zone.ts @@ -138,7 +138,7 @@ interface Zone { * * @returns {Zone} The parent Zone. */ - parent: Zone|null; + parent: Zone | null; /** * @returns {string} The Zone name (useful for debugging) */ @@ -162,7 +162,7 @@ interface Zone { * @param key The key to use for identification of the returned zone. * @returns {Zone} The Zone which defines the `key`, `null` if not found. */ - getZoneWith(key: string): Zone|null; + getZoneWith(key: string): Zone | null; /** * Used to create a child zone. * @@ -230,8 +230,8 @@ interface Zone { * @param customSchedule */ scheduleMicroTask( - source: string, callback: Function, data?: TaskData, - customSchedule?: (task: Task) => void): MicroTask; + source: string, callback: Function, data?: TaskData, + customSchedule?: (task: Task) => void): MicroTask; /** * Schedule a MacroTask. @@ -243,8 +243,8 @@ interface Zone { * @param customCancel */ scheduleMacroTask( - source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void, - customCancel?: (task: Task) => void): MacroTask; + source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void, + customCancel?: (task: Task) => void): MacroTask; /** * Schedule an EventTask. @@ -256,8 +256,8 @@ interface Zone { * @param customCancel */ scheduleEventTask( - source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void, - customCancel?: (task: Task) => void): EventTask; + source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void, + customCancel?: (task: Task) => void): EventTask; /** * Schedule an existing Task. @@ -290,7 +290,7 @@ interface ZoneType { /** * @returns {Task} The task associated with the current execution. */ - currentTask: Task|null; + currentTask: Task | null; /** * Verify that Zone has been correctly patched. Specifically that Promise is zone aware. @@ -321,19 +321,19 @@ interface _ZonePrivate { microtaskDrainDone: () => void; showUncaughtError: () => boolean; patchEventTarget: (global: any, apis: any[], options?: any) => boolean[]; - patchOnProperties: (obj: any, properties: string[]|null) => void; + patchOnProperties: (obj: any, properties: string[] | null) => void; patchThen: (ctro: Function) => void; setNativePromise: (nativePromise: any) => void; patchMethod: - (target: any, name: string, - patchFn: (delegate: Function, delegateName: string, name: string) => - (self: any, args: any[]) => any) => Function | null; + (target: any, name: string, + patchFn: (delegate: Function, delegateName: string, name: string) => + (self: any, args: any[]) => any) => Function | null; bindArguments: (args: any[], source: string) => any[]; } /** @internal */ interface _ZoneFrame { - parent: _ZoneFrame|null; + parent: _ZoneFrame | null; zone: Zone; } @@ -358,7 +358,7 @@ interface ZoneSpec { /** * A set of properties to be associated with Zone. Use [Zone.get] to retrieve them. */ - properties?: {[key: string]: any}; + properties?: { [key: string]: any }; /** * Allows the interception of zone forking. @@ -371,8 +371,8 @@ interface ZoneSpec { * @param zoneSpec The argument passed into the `fork` method. */ onFork?: - (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - zoneSpec: ZoneSpec) => Zone; + (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + zoneSpec: ZoneSpec) => Zone; /** * Allows interception of the wrapping of the callback. @@ -384,8 +384,8 @@ interface ZoneSpec { * @param source The argument passed into the `wrap` method. */ onIntercept?: - (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, delegate: Function, - source: string) => Function; + (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, delegate: Function, + source: string) => Function; /** * Allows interception of the callback invocation. @@ -399,8 +399,8 @@ interface ZoneSpec { * @param source The argument passed into the `run` method. */ onInvoke?: - (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, delegate: Function, - applyThis: any, applyArgs?: any[], source?: string) => any; + (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, delegate: Function, + applyThis: any, applyArgs?: any[], source?: string) => any; /** * Allows interception of the error handling. @@ -411,8 +411,8 @@ interface ZoneSpec { * @param error The argument passed into the `handleError` method. */ onHandleError?: - (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - error: any) => boolean; + (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + error: any) => boolean; /** * Allows interception of task scheduling. @@ -423,11 +423,11 @@ interface ZoneSpec { * @param task The argument passed into the `scheduleTask` method. */ onScheduleTask?: - (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task) => Task; + (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task) => Task; onInvokeTask?: - (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task, - applyThis: any, applyArgs?: any[]) => any; + (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task, + applyThis: any, applyArgs?: any[]) => any; /** * Allows interception of task cancellation. @@ -438,7 +438,7 @@ interface ZoneSpec { * @param task The argument passed into the `cancelTask` method. */ onCancelTask?: - (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task) => any; + (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task) => any; /** * Notifies of changes to the task queue empty status. @@ -449,8 +449,8 @@ interface ZoneSpec { * @param hasTaskState */ onHasTask?: - (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - hasTaskState: HasTaskState) => void; + (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + hasTaskState: HasTaskState) => void; } @@ -490,7 +490,7 @@ interface ZoneDelegate { fork(targetZone: Zone, zoneSpec: ZoneSpec): Zone; intercept(targetZone: Zone, callback: Function, source: string): Function; invoke(targetZone: Zone, callback: Function, applyThis?: any, applyArgs?: any[], source?: string): - any; + any; handleError(targetZone: Zone, error: any): boolean; scheduleTask(targetZone: Zone, task: Task): Task; invokeTask(targetZone: Zone, task: Task, applyThis?: any, applyArgs?: any[]): any; @@ -505,12 +505,12 @@ type HasTaskState = { /** * Task type: `microTask`, `macroTask`, `eventTask`. */ -type TaskType = 'microTask'|'macroTask'|'eventTask'; +type TaskType = 'microTask' | 'macroTask' | 'eventTask'; /** * Task type: `notScheduled`, `scheduling`, `scheduled`, `running`, `canceling`, 'unknown'. */ -type TaskState = 'notScheduled'|'scheduling'|'scheduled'|'running'|'canceling'|'unknown'; +type TaskState = 'notScheduled' | 'scheduling' | 'scheduled' | 'running' | 'canceling' | 'unknown'; /** @@ -633,9 +633,9 @@ type AmbientZone = Zone; /** @internal */ type AmbientZoneDelegate = ZoneDelegate; -const Zone: ZoneType = (function(global: any) { - const performance: {mark(name: string): void; measure(name: string, label: string): void;} = - global['performance']; +const Zone: ZoneType = (function (global: any) { + const performance: { mark(name: string): void; measure(name: string, label: string): void; } = + global['performance']; function mark(name: string) { performance && performance['mark'] && performance['mark'](name); } @@ -643,6 +643,7 @@ const Zone: ZoneType = (function(global: any) { performance && performance['measure'] && performance['measure'](name, label); } mark('Zone'); + const checkDuplicateZone = global[('__zone_symbol__forceDuplicateZoneCheck')] === true; if (global['Zone']) { // if global['Zone'] already exists (maybe zone.js was already loaded or // some other lib also registered a global object named Zone), we may need @@ -653,8 +654,7 @@ const Zone: ZoneType = (function(global: any) { // but when user load page2 again, error occurs because global['Zone'] already exists. // so we add a flag to let user choose whether to throw this error or not. // By default, if existing Zone is from zone.js, we will not throw the error. - if (global[('__zone_symbol__forceDuplicateZoneCheck')] === true || - typeof global['Zone'].__symbol__ !== 'function') { + if (checkDuplicateZone || typeof global['Zone'].__symbol__ !== 'function') { throw new Error('Zone already loaded.'); } else { return global['Zone']; @@ -667,11 +667,11 @@ const Zone: ZoneType = (function(global: any) { static assertZonePatched() { if (global['Promise'] !== patches['ZoneAwarePromise']) { throw new Error( - 'Zone.js has detected that ZoneAwarePromise `(window|global).Promise` ' + - 'has been overwritten.\n' + - 'Most likely cause is that a Promise polyfill has been loaded ' + - 'after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. ' + - 'If you must load one, do so before loading zone.js.)'); + 'Zone.js has detected that ZoneAwarePromise `(window|global).Promise` ' + + 'has been overwritten.\n' + + 'Most likely cause is that a Promise polyfill has been loaded ' + + 'after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. ' + + 'If you must load one, do so before loading zone.js.)'); } } @@ -687,13 +687,15 @@ const Zone: ZoneType = (function(global: any) { return _currentZoneFrame.zone; } - static get currentTask(): Task|null { + static get currentTask(): Task | null { return _currentTask; } static __load_patch(name: string, fn: _PatchFn): void { if (patches.hasOwnProperty(name)) { - throw Error('Already loaded patch: ' + name); + if (checkDuplicateZone) { + throw Error('Already loaded patch: ' + name); + } } else if (!global['__Zone_disable_' + name]) { const perfName = 'Zone:' + name; mark(perfName); @@ -702,7 +704,7 @@ const Zone: ZoneType = (function(global: any) { } } - public get parent(): AmbientZone|null { + public get parent(): AmbientZone | null { return this._parent; } @@ -711,17 +713,17 @@ const Zone: ZoneType = (function(global: any) { } - private _parent: Zone|null; + private _parent: Zone | null; private _name: string; - private _properties: {[key: string]: any}; + private _properties: { [key: string]: any }; private _zoneDelegate: ZoneDelegate; - constructor(parent: Zone|null, zoneSpec: ZoneSpec|null) { + constructor(parent: Zone | null, zoneSpec: ZoneSpec | null) { this._parent = parent; this._name = zoneSpec ? zoneSpec.name || 'unnamed' : ''; this._properties = zoneSpec && zoneSpec.properties || {}; this._zoneDelegate = - new ZoneDelegate(this, this._parent && this._parent._zoneDelegate, zoneSpec); + new ZoneDelegate(this, this._parent && this._parent._zoneDelegate, zoneSpec); } public get(key: string): any { @@ -729,8 +731,8 @@ const Zone: ZoneType = (function(global: any) { if (zone) return zone._properties[key]; } - public getZoneWith(key: string): AmbientZone|null { - let current: Zone|null = this; + public getZoneWith(key: string): AmbientZone | null { + let current: Zone | null = this; while (current) { if (current._properties.hasOwnProperty(key)) { return current; @@ -751,15 +753,15 @@ const Zone: ZoneType = (function(global: any) { } const _callback = this._zoneDelegate.intercept(this, callback, source); const zone: Zone = this; - return function() { + return function () { return zone.runGuarded(_callback, (this as any), arguments, source); } as any as T; } public run(callback: Function, applyThis?: any, applyArgs?: any[], source?: string): any; public run( - callback: (...args: any[]) => T, applyThis?: any, applyArgs?: any[], source?: string): T { - _currentZoneFrame = {parent: _currentZoneFrame, zone: this}; + callback: (...args: any[]) => T, applyThis?: any, applyArgs?: any[], source?: string): T { + _currentZoneFrame = { parent: _currentZoneFrame, zone: this }; try { return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source); } finally { @@ -769,9 +771,9 @@ const Zone: ZoneType = (function(global: any) { public runGuarded(callback: Function, applyThis?: any, applyArgs?: any[], source?: string): any; public runGuarded( - callback: (...args: any[]) => T, applyThis: any = null, applyArgs?: any[], - source?: string) { - _currentZoneFrame = {parent: _currentZoneFrame, zone: this}; + callback: (...args: any[]) => T, applyThis: any = null, applyArgs?: any[], + source?: string) { + _currentZoneFrame = { parent: _currentZoneFrame, zone: this }; try { try { return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source); @@ -789,8 +791,8 @@ const Zone: ZoneType = (function(global: any) { runTask(task: Task, applyThis?: any, applyArgs?: any): any { if (task.zone != this) { throw new Error( - 'A task can only be run in the zone of creation! (Creation: ' + - (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')'); + 'A task can only be run in the zone of creation! (Creation: ' + + (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')'); } // https://github.com/angular/zone.js/issues/778, sometimes eventTask // will run in notScheduled(canceled) state, we should not try to @@ -805,7 +807,7 @@ const Zone: ZoneType = (function(global: any) { task.runCount++; const previousTask = _currentTask; _currentTask = task; - _currentZoneFrame = {parent: _currentZoneFrame, zone: this}; + _currentZoneFrame = { parent: _currentZoneFrame, zone: this }; try { if (task.type == macroTask && task.data && !task.data.isPeriodic) { task.cancelFn = undefined; @@ -827,7 +829,7 @@ const Zone: ZoneType = (function(global: any) { task.runCount = 0; this._updateTaskCount(task as ZoneTask, -1); reEntryGuard && - (task as ZoneTask)._transitionTo(notScheduled, running, notScheduled); + (task as ZoneTask)._transitionTo(notScheduled, running, notScheduled); } } _currentZoneFrame = _currentZoneFrame.parent!; @@ -843,7 +845,7 @@ const Zone: ZoneType = (function(global: any) { while (newZone) { if (newZone === task.zone) { throw Error(`can not reschedule task to ${ - this.name} which is descendants of the original zone ${task.zone.name}`); + this.name} which is descendants of the original zone ${task.zone.name}`); } newZone = newZone.parent; } @@ -873,31 +875,31 @@ const Zone: ZoneType = (function(global: any) { } scheduleMicroTask( - source: string, callback: Function, data?: TaskData, - customSchedule?: (task: Task) => void): MicroTask { + source: string, callback: Function, data?: TaskData, + customSchedule?: (task: Task) => void): MicroTask { return this.scheduleTask( - new ZoneTask(microTask, source, callback, data, customSchedule, undefined)); + new ZoneTask(microTask, source, callback, data, customSchedule, undefined)); } scheduleMacroTask( - source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void, - customCancel?: (task: Task) => void): MacroTask { + source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void, + customCancel?: (task: Task) => void): MacroTask { return this.scheduleTask( - new ZoneTask(macroTask, source, callback, data, customSchedule, customCancel)); + new ZoneTask(macroTask, source, callback, data, customSchedule, customCancel)); } scheduleEventTask( - source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void, - customCancel?: (task: Task) => void): EventTask { + source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void, + customCancel?: (task: Task) => void): EventTask { return this.scheduleTask( - new ZoneTask(eventTask, source, callback, data, customSchedule, customCancel)); + new ZoneTask(eventTask, source, callback, data, customSchedule, customCancel)); } cancelTask(task: Task): any { if (task.zone != this) throw new Error( - 'A task can only be cancelled in the zone of creation! (Creation: ' + - (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')'); + 'A task can only be cancelled in the zone of creation! (Creation: ' + + (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')'); (task as ZoneTask)._transitionTo(canceling, scheduled, running); try { this._zoneDelegate.cancelTask(this, task); @@ -927,62 +929,64 @@ const Zone: ZoneType = (function(global: any) { const DELEGATE_ZS: ZoneSpec = { name: '', onHasTask: - (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, - hasTaskState: HasTaskState): void => delegate.hasTask(target, hasTaskState), + (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, + hasTaskState: HasTaskState): void => delegate.hasTask(target, hasTaskState), onScheduleTask: - (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, task: Task): Task => - delegate.scheduleTask(target, task), + (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, task: Task): Task => + delegate.scheduleTask(target, task), onInvokeTask: - (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, task: Task, - applyThis: any, applyArgs: any): any => - delegate.invokeTask(target, task, applyThis, applyArgs), + (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, task: Task, + applyThis: any, applyArgs: any): any => + delegate.invokeTask(target, task, applyThis, applyArgs), onCancelTask: (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, task: Task): - any => delegate.cancelTask(target, task) + any => delegate.cancelTask(target, task) }; class ZoneDelegate implements AmbientZoneDelegate { public zone: Zone; - private _taskCounts: {microTask: number, - macroTask: number, - eventTask: number} = {'microTask': 0, 'macroTask': 0, 'eventTask': 0}; + private _taskCounts: { + microTask: number, + macroTask: number, + eventTask: number + } = { 'microTask': 0, 'macroTask': 0, 'eventTask': 0 }; - private _parentDelegate: ZoneDelegate|null; + private _parentDelegate: ZoneDelegate | null; - private _forkDlgt: ZoneDelegate|null; - private _forkZS: ZoneSpec|null; - private _forkCurrZone: Zone|null; + private _forkDlgt: ZoneDelegate | null; + private _forkZS: ZoneSpec | null; + private _forkCurrZone: Zone | null; - private _interceptDlgt: ZoneDelegate|null; - private _interceptZS: ZoneSpec|null; - private _interceptCurrZone: Zone|null; + private _interceptDlgt: ZoneDelegate | null; + private _interceptZS: ZoneSpec | null; + private _interceptCurrZone: Zone | null; - private _invokeDlgt: ZoneDelegate|null; - private _invokeZS: ZoneSpec|null; - private _invokeCurrZone: Zone|null; + private _invokeDlgt: ZoneDelegate | null; + private _invokeZS: ZoneSpec | null; + private _invokeCurrZone: Zone | null; - private _handleErrorDlgt: ZoneDelegate|null; - private _handleErrorZS: ZoneSpec|null; - private _handleErrorCurrZone: Zone|null; + private _handleErrorDlgt: ZoneDelegate | null; + private _handleErrorZS: ZoneSpec | null; + private _handleErrorCurrZone: Zone | null; - private _scheduleTaskDlgt: ZoneDelegate|null; - private _scheduleTaskZS: ZoneSpec|null; - private _scheduleTaskCurrZone: Zone|null; + private _scheduleTaskDlgt: ZoneDelegate | null; + private _scheduleTaskZS: ZoneSpec | null; + private _scheduleTaskCurrZone: Zone | null; - private _invokeTaskDlgt: ZoneDelegate|null; - private _invokeTaskZS: ZoneSpec|null; - private _invokeTaskCurrZone: Zone|null; + private _invokeTaskDlgt: ZoneDelegate | null; + private _invokeTaskZS: ZoneSpec | null; + private _invokeTaskCurrZone: Zone | null; - private _cancelTaskDlgt: ZoneDelegate|null; - private _cancelTaskZS: ZoneSpec|null; - private _cancelTaskCurrZone: Zone|null; + private _cancelTaskDlgt: ZoneDelegate | null; + private _cancelTaskZS: ZoneSpec | null; + private _cancelTaskCurrZone: Zone | null; - private _hasTaskDlgt: ZoneDelegate|null; - private _hasTaskDlgtOwner: ZoneDelegate|null; - private _hasTaskZS: ZoneSpec|null; - private _hasTaskCurrZone: Zone|null; + private _hasTaskDlgt: ZoneDelegate | null; + private _hasTaskDlgtOwner: ZoneDelegate | null; + private _hasTaskZS: ZoneSpec | null; + private _hasTaskCurrZone: Zone | null; - constructor(zone: Zone, parentDelegate: ZoneDelegate|null, zoneSpec: ZoneSpec|null) { + constructor(zone: Zone, parentDelegate: ZoneDelegate | null, zoneSpec: ZoneSpec | null) { this.zone = zone; this._parentDelegate = parentDelegate; @@ -991,44 +995,44 @@ const Zone: ZoneType = (function(global: any) { this._forkCurrZone = zoneSpec && (zoneSpec.onFork ? this.zone : parentDelegate!.zone); this._interceptZS = - zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate!._interceptZS); + zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate!._interceptZS); this._interceptDlgt = - zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate!._interceptDlgt); + zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate!._interceptDlgt); this._interceptCurrZone = - zoneSpec && (zoneSpec.onIntercept ? this.zone : parentDelegate!.zone); + zoneSpec && (zoneSpec.onIntercept ? this.zone : parentDelegate!.zone); this._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate!._invokeZS); this._invokeDlgt = - zoneSpec && (zoneSpec.onInvoke ? parentDelegate! : parentDelegate!._invokeDlgt); + zoneSpec && (zoneSpec.onInvoke ? parentDelegate! : parentDelegate!._invokeDlgt); this._invokeCurrZone = zoneSpec && (zoneSpec.onInvoke ? this.zone : parentDelegate!.zone); this._handleErrorZS = - zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate!._handleErrorZS); + zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate!._handleErrorZS); this._handleErrorDlgt = - zoneSpec && (zoneSpec.onHandleError ? parentDelegate! : parentDelegate!._handleErrorDlgt); + zoneSpec && (zoneSpec.onHandleError ? parentDelegate! : parentDelegate!._handleErrorDlgt); this._handleErrorCurrZone = - zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate!.zone); + zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate!.zone); this._scheduleTaskZS = - zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate!._scheduleTaskZS); + zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate!._scheduleTaskZS); this._scheduleTaskDlgt = zoneSpec && - (zoneSpec.onScheduleTask ? parentDelegate! : parentDelegate!._scheduleTaskDlgt); + (zoneSpec.onScheduleTask ? parentDelegate! : parentDelegate!._scheduleTaskDlgt); this._scheduleTaskCurrZone = - zoneSpec && (zoneSpec.onScheduleTask ? this.zone : parentDelegate!.zone); + zoneSpec && (zoneSpec.onScheduleTask ? this.zone : parentDelegate!.zone); this._invokeTaskZS = - zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate!._invokeTaskZS); + zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate!._invokeTaskZS); this._invokeTaskDlgt = - zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate! : parentDelegate!._invokeTaskDlgt); + zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate! : parentDelegate!._invokeTaskDlgt); this._invokeTaskCurrZone = - zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate!.zone); + zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate!.zone); this._cancelTaskZS = - zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate!._cancelTaskZS); + zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate!._cancelTaskZS); this._cancelTaskDlgt = - zoneSpec && (zoneSpec.onCancelTask ? parentDelegate! : parentDelegate!._cancelTaskDlgt); + zoneSpec && (zoneSpec.onCancelTask ? parentDelegate! : parentDelegate!._cancelTaskDlgt); this._cancelTaskCurrZone = - zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate!.zone); + zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate!.zone); this._hasTaskZS = null; this._hasTaskDlgt = null; @@ -1064,30 +1068,30 @@ const Zone: ZoneType = (function(global: any) { fork(targetZone: Zone, zoneSpec: ZoneSpec): AmbientZone { return this._forkZS ? this._forkZS.onFork!(this._forkDlgt!, this.zone, targetZone, zoneSpec) : - new Zone(targetZone, zoneSpec); + new Zone(targetZone, zoneSpec); } intercept(targetZone: Zone, callback: Function, source: string): Function { return this._interceptZS ? - this._interceptZS.onIntercept! + this._interceptZS.onIntercept! (this._interceptDlgt!, this._interceptCurrZone!, targetZone, callback, source) : - callback; + callback; } invoke( - targetZone: Zone, callback: Function, applyThis: any, applyArgs?: any[], - source?: string): any { + targetZone: Zone, callback: Function, applyThis: any, applyArgs?: any[], + source?: string): any { return this._invokeZS ? this._invokeZS.onInvoke! - (this._invokeDlgt!, this._invokeCurrZone!, targetZone, callback, - applyThis, applyArgs, source) : - callback.apply(applyThis, applyArgs); + (this._invokeDlgt!, this._invokeCurrZone!, targetZone, callback, + applyThis, applyArgs, source) : + callback.apply(applyThis, applyArgs); } handleError(targetZone: Zone, error: any): boolean { return this._handleErrorZS ? - this._handleErrorZS.onHandleError! + this._handleErrorZS.onHandleError! (this._handleErrorDlgt!, this._handleErrorCurrZone!, targetZone, error) : - true; + true; } scheduleTask(targetZone: Zone, task: Task): Task { @@ -1097,8 +1101,8 @@ const Zone: ZoneType = (function(global: any) { returnTask._zoneDelegates!.push(this._hasTaskDlgtOwner!); } returnTask = this._scheduleTaskZS.onScheduleTask! - (this._scheduleTaskDlgt!, this._scheduleTaskCurrZone!, targetZone, task) as - ZoneTask; + (this._scheduleTaskDlgt!, this._scheduleTaskCurrZone!, targetZone, task) as + ZoneTask; if (!returnTask) returnTask = task as ZoneTask; } else { if (task.scheduleFn) { @@ -1114,16 +1118,16 @@ const Zone: ZoneType = (function(global: any) { invokeTask(targetZone: Zone, task: Task, applyThis: any, applyArgs?: any[]): any { return this._invokeTaskZS ? this._invokeTaskZS.onInvokeTask! - (this._invokeTaskDlgt!, this._invokeTaskCurrZone!, targetZone, - task, applyThis, applyArgs) : - task.callback.apply(applyThis, applyArgs); + (this._invokeTaskDlgt!, this._invokeTaskCurrZone!, targetZone, + task, applyThis, applyArgs) : + task.callback.apply(applyThis, applyArgs); } cancelTask(targetZone: Zone, task: Task): any { let value: any; if (this._cancelTaskZS) { value = this._cancelTaskZS.onCancelTask! - (this._cancelTaskDlgt!, this._cancelTaskCurrZone!, targetZone, task); + (this._cancelTaskDlgt!, this._cancelTaskCurrZone!, targetZone, task); } else { if (!task.cancelFn) { throw Error('Task is not cancelable'); @@ -1138,7 +1142,7 @@ const Zone: ZoneType = (function(global: any) { // can still trigger hasTask callback try { this._hasTaskZS && - this._hasTaskZS.onHasTask! + this._hasTaskZS.onHasTask! (this._hasTaskDlgt!, this._hasTaskCurrZone!, targetZone, isEmpty); } catch (err) { this.handleError(targetZone, err); @@ -1169,17 +1173,17 @@ const Zone: ZoneType = (function(global: any) { public source: string; public invoke: Function; public callback: Function; - public data: TaskData|undefined; - public scheduleFn: ((task: Task) => void)|undefined; - public cancelFn: ((task: Task) => void)|undefined; - _zone: Zone|null = null; + public data: TaskData | undefined; + public scheduleFn: ((task: Task) => void) | undefined; + public cancelFn: ((task: Task) => void) | undefined; + _zone: Zone | null = null; public runCount: number = 0; - _zoneDelegates: ZoneDelegate[]|null = null; + _zoneDelegates: ZoneDelegate[] | null = null; _state: TaskState = 'notScheduled'; constructor( - type: T, source: string, callback: Function, options: TaskData|undefined, - scheduleFn: ((task: Task) => void)|undefined, cancelFn: ((task: Task) => void)|undefined) { + type: T, source: string, callback: Function, options: TaskData | undefined, + scheduleFn: ((task: Task) => void) | undefined, cancelFn: ((task: Task) => void) | undefined) { this.type = type; this.source = source; this.data = options; @@ -1191,7 +1195,7 @@ const Zone: ZoneType = (function(global: any) { if (type === eventTask && options && (options as any).useG) { this.invoke = ZoneTask.invokeTask; } else { - this.invoke = function() { + this.invoke = function () { return ZoneTask.invokeTask.call(global, self, this, arguments); }; } @@ -1233,8 +1237,8 @@ const Zone: ZoneType = (function(global: any) { } } else { throw new Error(`${this.type} '${this.source}': can not transition to '${ - toState}', expecting state '${fromState1}'${ - fromState2 ? ' or \'' + fromState2 + '\'' : ''}, was '${this._state}'.`); + toState}', expecting state '${fromState1}'${ + fromState2 ? ' or \'' + fromState2 + '\'' : ''}, was '${this._state}'.`); } } @@ -1323,14 +1327,14 @@ const Zone: ZoneType = (function(global: any) { ////////////////////////////////////////////////////// - const NO_ZONE = {name: 'NO ZONE'}; + const NO_ZONE = { name: 'NO ZONE' }; const notScheduled: 'notScheduled' = 'notScheduled', scheduling: 'scheduling' = 'scheduling', - scheduled: 'scheduled' = 'scheduled', running: 'running' = 'running', - canceling: 'canceling' = 'canceling', unknown: 'unknown' = 'unknown'; + scheduled: 'scheduled' = 'scheduled', running: 'running' = 'running', + canceling: 'canceling' = 'canceling', unknown: 'unknown' = 'unknown'; const microTask: 'microTask' = 'microTask', macroTask: 'macroTask' = 'macroTask', - eventTask: 'eventTask' = 'eventTask'; + eventTask: 'eventTask' = 'eventTask'; - const patches: {[key: string]: any} = {}; + const patches: { [key: string]: any } = {}; const _api: _ZonePrivate = { symbol: __symbol__, currentZoneFrame: () => _currentZoneFrame, @@ -1352,11 +1356,11 @@ const Zone: ZoneType = (function(global: any) { } }, }; - let _currentZoneFrame: _ZoneFrame = {parent: null, zone: new Zone(null, null)}; - let _currentTask: Task|null = null; + let _currentZoneFrame: _ZoneFrame = { parent: null, zone: new Zone(null, null) }; + let _currentTask: Task | null = null; let _numberOfNestedTaskFrames = 0; - function noop() {} + function noop() { } function __symbol__(name: string) { return '__zone_symbol__' + name;