Skip to content

Instantly share code, notes, and snippets.

View arturovt's full-sized avatar
🎯

Artur arturovt

🎯
View GitHub Profile
interface ZoneSpec {
/**
* Название зоны
*/
name: string;
/**
* Свойства, которые можно ассоциировать с этой зоной
*/
properties?: {
[key: string]: any;
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) {
class Zone {
public run<T>(
callback: (...args: any[]) => T,
applyThis?: any,
applyArgs?: any,
source?: string
): T {
_currentZoneFrame = {
parent: _currentZoneFrame,
zone: this
class ZoneDelegate {
public invoke(
targetZone: Zone,
callback: Function,
applyThis: any,
applyArgs?: any[],
source?: string
): any {
if (this._invokeZS) {
return this._invokeZS.onInvoke!(
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
};
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`
// хранится в кеше и удаляется по завершении
function scheduleMacroTaskWithCurrentZone(source, callback, data, customSchedule, customCancel) {
return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel);
}
class Zone {
public scheduleMacroTask(source, callback, data, customSchedule, customCancel) {
return this.scheduleTask(
new ZoneTask(macroTask, source, callback, data, customSchedule, customCancel)
);
}
}
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) {
type HasTaskState = {
microTask: boolean;
macroTask: boolean;
eventTask: boolean;
change: TaskType;
};
type TaskType = 'microTask' | 'macroTask' | 'eventTask';