Skip to content

Commit

Permalink
test: update ng_zone hasPendingMicrotasks logic
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Jun 1, 2019
1 parent bf157d4 commit 36e5659
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
14 changes: 9 additions & 5 deletions packages/core/src/zone/ng_zone.ts
Expand Up @@ -7,8 +7,10 @@
*/

import {EventEmitter} from '../event_emitter';
import {global} from '../util/global';
import {nativeRequestAnimationFrame} from '../util/raf';


/**
* An injectable service for executing work inside or outside of the Angular zone.
*
Expand Down Expand Up @@ -264,11 +266,12 @@ function delayChangeDetectionForEvents(zone: NgZonePrivate) {
if (zone.lastRequestAnimationFrameId !== -1) {
return;
}
zone.lastRequestAnimationFrameId = nativeRequestAnimationFrame(() => {
zone.lastRequestAnimationFrameId = nativeRequestAnimationFrame.call(global, () => {
zone.lastRequestAnimationFrameId = -1;
updateMicroTaskStatus(zone);
checkStable(zone);
});
updateMicroTaskStatus(zone, zone.hasPendingMicrotasks);
updateMicroTaskStatus(zone);
}

function forkInnerZoneWithAngularBehavior(zone: NgZonePrivate) {
Expand Down Expand Up @@ -310,7 +313,8 @@ function forkInnerZoneWithAngularBehavior(zone: NgZonePrivate) {
// 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') {
updateMicroTaskStatus(zone, hasTaskState.microTask);
zone._hasPendingMicrotasks = hasTaskState.microTask;
updateMicroTaskStatus(zone);
checkStable(zone);
} else if (hasTaskState.change == 'macroTask') {
zone.hasPendingMacrotasks = hasTaskState.macroTask;
Expand All @@ -326,8 +330,8 @@ function forkInnerZoneWithAngularBehavior(zone: NgZonePrivate) {
});
}

function updateMicroTaskStatus(zone: NgZonePrivate, hasPendingMicrotasks: boolean) {
if (hasPendingMicrotasks ||
function updateMicroTaskStatus(zone: NgZonePrivate) {
if (zone._hasPendingMicrotasks ||
(zone.shouldCoalesceEventChangeDetection && zone.lastRequestAnimationFrameId !== -1)) {
zone.hasPendingMicrotasks = true;
} else {
Expand Down
Expand Up @@ -340,10 +340,7 @@ import {el} from '../../../testing/src/browser_util';
removerChild = manager.addEventListener(child, 'click', handler);
removerParent = manager.addEventListener(element, 'click', handler);
});
zone.onStable.subscribe((isStable: any) => {
console.log('stable triggered');
stables.push(isStable);
});
zone.onStable.subscribe((isStable: any) => { stables.push(isStable); });
getDOM().dispatchEvent(child, dispatchedEvent);
requestAnimationFrame(() => {
expect(receivedEvents.length).toBe(2);
Expand Down

0 comments on commit 36e5659

Please sign in to comment.