Skip to content

Commit

Permalink
Merge branch 'master' into stale_props_scu
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Mar 7, 2019
2 parents 2081017 + c66ec75 commit 33618f5
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions hooks/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,31 +186,29 @@ export function useContext(context) {
*/
let afterPaint = () => {};

/** @type {MessageChannel} */
let mc;
/**
* After paint effects consumer.
*/
function flushAfterPaintEffects() {
afterPaintEffects.forEach(component => {
component._afterPaintQueued = false;
if (!component._parentDom) return;
component.__hooks._pendingEffects.forEach(invokeEffect);
component.__hooks._pendingEffects = [];
});
afterPaintEffects = [];
}

function onPaint() {
mc.port1.postMessage(undefined);
function scheduleFlushAfterPaint() {
setTimeout(flushAfterPaintEffects, 0);
}

if (typeof window !== 'undefined') {
mc = new MessageChannel();

afterPaint = (component) => {
if (!component._afterPaintQueued && (component._afterPaintQueued = true) && afterPaintEffects.push(component) === 1) {
requestAnimationFrame(onPaint);
requestAnimationFrame(scheduleFlushAfterPaint);
}
};

mc.port2.onmessage = () => {
afterPaintEffects.forEach(component => {
component._afterPaintQueued = false;
if (!component._parentDom) return;
component.__hooks._pendingEffects.forEach(invokeEffect);
component.__hooks._pendingEffects = [];
});
afterPaintEffects = [];
};
}

/**
Expand Down

0 comments on commit 33618f5

Please sign in to comment.