From efc9dc343cac7c2d301b9ba858a51e7ec522be30 Mon Sep 17 00:00:00 2001 From: 132yse <1533540012@qq.com> Date: Tue, 31 Dec 2019 18:30:22 +0800 Subject: [PATCH] rollup requestAnimationFrame --- src/scheduler.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/scheduler.js b/src/scheduler.js index d928f466..48f345dc 100644 --- a/src/scheduler.js +++ b/src/scheduler.js @@ -55,16 +55,9 @@ function flushWork() { export const planWork = (() => { if (typeof MessageChannel !== 'undefined') { - const channel = new MessageChannel() - return cb => { - if (cb) { - channel.port2.onmessage = cb - channel.port1.postMessage(null) - } else { - channel.port1.onmessage = flushWork - channel.port2.postMessage(null) - } - } + const { port1, port2 } = new MessageChannel() + port1.onmessage = flushWork + return cb => (cb ? requestAnimationFrame(cb) : port2.postMessage(null)) } return cb => setTimeout(cb || flushWork) })()