Skip to content

Instantly share code, notes, and snippets.

@toymakerlabs
Created November 28, 2016 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toymakerlabs/eb16b3ec5d7cb6051af2f4d00f2e4911 to your computer and use it in GitHub Desktop.
Save toymakerlabs/eb16b3ec5d7cb6051af2f4d00f2e4911 to your computer and use it in GitHub Desktop.
Comparison of refactored Functional wrapper for requestAnimationFrame
/* FP
const loopy = (start_time,duration,onEnterFrame) => {
window.requestAnimationFrame((timestamp)=>{
if(start_time === 0) start_time = timestamp; //only true the first run through
//const step = getStep(timestamp,start_time,duration)
//console.log(timestamp-last_time)
//const delta = Math.min(timestamp-last_time,17)
onEnterFrame(Math.min(timestamp - start_time, duration))
if((timestamp-start_time)<duration) {
//stop before the last frame
loopy(start_time,duration,onEnterFrame);
}
});
}
export const animationFrameLoop = (duration,cb=()=>{}) =>{
loopy(0,duration,cb)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment