into-piece / Step-By-Step

每天一题向前端架构师前进
4 stars 1 forks source link

react-scheduler #16

Open into-piece opened 5 years ago

into-piece commented 5 years ago

源码学习开始

into-piece commented 4 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。