Skip to content

Instantly share code, notes, and snippets.

@arturovt
Last active July 27, 2019 16:34
Show Gist options
  • Save arturovt/afba223199c2d220e0ea45925fbd0219 to your computer and use it in GitHub Desktop.
Save arturovt/afba223199c2d220e0ea45925fbd0219 to your computer and use it in GitHub Desktop.
function forkInnerZoneWithAngularBehavior(zone) {
zone._inner = zone._inner.fork({
name: 'angular',
properties: { isAngularZone: true },
onInvokeTask: (delegate, current, target, task, applyThis, applyArgs) => {
try {
onEnter(zone);
return delegate.invokeTask(target, task, applyThis, applyArgs);
} finally {
onLeave(zone);
}
},
onInvoke: (delegate, current, target, callback, applyThis, applyArgs, source) => {
try {
onEnter(zone);
return delegate.invoke(target, callback, applyThis, applyArgs, source);
} finally {
onLeave(zone);
}
},
onHasTask: (delegate, current, target, hasTaskState) => {
delegate.hasTask(target, hasTaskState);
if (current === target) {
// We are only interested in hasTask events which originate from our zone
// (A child hasTask event is not interesting to us)
if (hasTaskState.change == 'microTask') {
zone.hasPendingMicrotasks = hasTaskState.microTask;
checkStable(zone);
} else if (hasTaskState.change == 'macroTask') {
zone.hasPendingMacrotasks = hasTaskState.macroTask;
}
}
},
onHandleError: (delegate, current, target, error) => {
delegate.handleError(target, error);
zone.runOutsideAngular(() => zone.onError.emit(error));
return false;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment