Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. const rafScheduler = (fn) => {
  2. let lastArgs = [];
  3. let frameId = null;
  4.  
  5. return (...args) => {
  6. // Always capture the latest value
  7. lastArgs = args;
  8.  
  9. // There is already a frame queued
  10. if (frameId) {
  11. return frameId;
  12. }
  13.  
  14. // Schedule a new frame
  15. frameId = requestAnimationFrame(() => {
  16. frameId = null;
  17. fn(...lastArgs);
  18. });
  19.  
  20. return frameId;
  21. };
  22. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement