Open into-piece opened 5 years ago
// This is a built-in polyfill for requestIdleCallback. It works by scheduling // a requestAnimationFrame, storing the time for the start of the frame, then // scheduling a postMessage which gets scheduled after paint. Within the // postMessage handler do as much work as possible until time + frame rate. // By separating the idle call into a separate event tick we ensure that // layout, paint and other browser work is counted against the available time. // The frame rate is dynamically adjusted.
这里内部实现了兼容的requestIdleCallback,它通过调度一个requestAnimationFrame,存储框架开始的时间,然后调度一个可以在绘制之后获取调度信息的postMessage。
源码学习开始