Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const rafScheduler = (fn) => {
- let lastArgs = [];
- let frameId = null;
- return (...args) => {
- // Always capture the latest value
- lastArgs = args;
- // There is already a frame queued
- if (frameId) {
- return frameId;
- }
- // Schedule a new frame
- frameId = requestAnimationFrame(() => {
- frameId = null;
- fn(...lastArgs);
- });
- return frameId;
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement