This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ZoneSpec { | |
/** | |
* Название зоны | |
*/ | |
name: string; | |
/** | |
* Свойства, которые можно ассоциировать с этой зоной | |
*/ | |
properties?: { | |
[key: string]: any; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myFirstZone = Zone.current.fork({ | |
name: 'моя первая зона', | |
onInvoke(parentZoneDelegate, _, targetZone, delegate, applyThis, applyArgs, source) { | |
console.log('Где-то вызвался метод run...'); | |
return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source); | |
}, | |
onScheduleTask(parentZoneDelegate, _, targetZone, task) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Zone { | |
public run<T>( | |
callback: (...args: any[]) => T, | |
applyThis?: any, | |
applyArgs?: any, | |
source?: string | |
): T { | |
_currentZoneFrame = { | |
parent: _currentZoneFrame, | |
zone: this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ZoneDelegate { | |
public invoke( | |
targetZone: Zone, | |
callback: Function, | |
applyThis: any, | |
applyArgs?: any[], | |
source?: string | |
): any { | |
if (this._invokeZS) { | |
return this._invokeZS.onInvoke!( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patchMethod(window, setName, function(delegate) { | |
return function(self, args) { | |
if (typeof args[0] === 'function') { | |
var options = { | |
handleId: null, | |
isPeriodic: nameSuffix === 'Interval', | |
delay: nameSuffix === 'Interval' || nameSuffix === 'Timeout' ? args[1] || 0 : null, | |
args: args | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function scheduleTask(task) { | |
var data = task.data; | |
function timer() { | |
try { | |
task.invoke.apply(this, arguments); | |
} finally { | |
if (!(task.data && task.data.isPeriodic)) { | |
if (typeof data.handleId === 'number') { | |
// в не nodejs окружении `timerId` | |
// хранится в кеше и удаляется по завершении |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function scheduleMacroTaskWithCurrentZone(source, callback, data, customSchedule, customCancel) { | |
return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Zone { | |
public scheduleMacroTask(source, callback, data, customSchedule, customCancel) { | |
return this.scheduleTask( | |
new ZoneTask(macroTask, source, callback, data, customSchedule, customCancel) | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myFirstZone = Zone.current.fork({ | |
name: 'моя первая зона', | |
onInvoke(parentZoneDelegate, _, targetZone, delegate, applyThis, applyArgs, source) { | |
console.log('Где-то вызвался метод run...'); | |
return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source); | |
}, | |
onScheduleTask(parentZoneDelegate, _, targetZone, task) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type HasTaskState = { | |
microTask: boolean; | |
macroTask: boolean; | |
eventTask: boolean; | |
change: TaskType; | |
}; | |
type TaskType = 'microTask' | 'macroTask' | 'eventTask'; |