Created
October 20, 2020 17:34
-
-
Save gordonbrander/b1a404a522df7c1e4f9aa7eaa3a801dd to your computer and use it in GitHub Desktop.
FrameScheduler - a frame scheduler that will call callback at most once per frame.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creates a frame scheduler that will call callback at most once per frame. | |
export const FrameScheduler = callback => { | |
let isScheduled = false | |
const draw = t => { | |
isScheduled = false | |
callback(t) | |
} | |
const schedule = () => { | |
if (!isScheduled) { | |
isScheduled = true | |
requestAnimationFrame(draw) | |
} | |
} | |
return schedule | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment