Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/zones.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,15 @@ const zoneWrapFn = (it: (...args: any[]) => any, macrotask: MacroTask|undefined)
// function() is needed for the arguments object
// tslint:disable-next-line:only-arrow-functions
return function() {
const _arguments = arguments;
if (macrotask) {
setTimeout(() => {
if (macrotask.state === 'scheduled') {
macrotask.invoke();
}
}, 10);
}
return run(() => it.apply(_this, arguments));
return run(() => it.apply(_this, _arguments));
};
};

Expand All @@ -161,18 +162,19 @@ export const ɵzoneWrap = <T= unknown>(it: T, blockUntilFirst: boolean): T => {
// tslint:disable-next-line:only-arrow-functions
return function() {
let macrotask: MacroTask | undefined;
const _arguments = arguments;
// if this is a callback function, e.g, onSnapshot, we should create a microtask and invoke it
// only once one of the callback functions is tripped.
for (let i = 0; i < arguments.length; i++) {
if (typeof arguments[i] === 'function') {
if (typeof _arguments[i] === 'function') {
if (blockUntilFirst) {
macrotask ||= run(() => Zone.current.scheduleMacroTask('firebaseZoneBlock', noop, {}, noop, noop));
}
// TODO create a microtask to track callback functions
arguments[i] = zoneWrapFn(arguments[i], macrotask);
_arguments[i] = zoneWrapFn(_arguments[i], macrotask);
}
}
const ret = runOutsideAngular(() => (it as any).apply(this, arguments));
const ret = runOutsideAngular(() => (it as any).apply(this, _arguments));
if (!blockUntilFirst) {
if (ret instanceof Observable) {
const schedulers = getSchedulers();
Expand Down