Created
November 28, 2016 16:20
-
-
Save toymakerlabs/eb16b3ec5d7cb6051af2f4d00f2e4911 to your computer and use it in GitHub Desktop.
Comparison of refactored Functional wrapper for requestAnimationFrame
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
/* 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