In summary I've turned frame(fn) into a function that takes a render-function and puts it into the animation queue (or makes a queue if required). The function is then called with 2 arguments, (1) is the time-delta from the start of the animation, and (2) a callback that can be used to resubmit the render-function to the same queue.
When first loaded, frame will be the most basic version that does setTimeout and delta-calculation itself; meanwhile it runs a feature-detect on a requestAnimationFrame to see what kind of argument it provides. The alternatives allowed for are (1) standard epoch-Date-based timestamp and (2) performance.now()-based timestamp. If it finds an rAF that works like this, it replaces frame with an appropriate rAF-based alternative.
This should be pretty future-proof as the fallback should always work. However there may be a need to enhance it in future. e.g. if Mozilla's animationStartTime gets traction or if other browsers start using performance.now()-based timestamps and vendor-prefix now (note though that that won't break this implementation, they'll just fall back to the basic implementation).
I've also imported Bonzo's .jshintrc and I've added a test to ensure that duration is roughly obeyed, this should help detect shortcutting.
will close this for now, am happy with @danro's fix in #38 for the immediate problem, I'll see if I can find time to work on this one a bit more and improve it.
A.K.A. uber-feature-detect
Further to the discussion @ #36 (/cc @danro)
In summary I've turned
frame(fn)
into a function that takes a render-function and puts it into the animation queue (or makes a queue if required). The function is then called with 2 arguments, (1) is the time-delta from the start of the animation, and (2) a callback that can be used to resubmit the render-function to the same queue.When first loaded,
frame
will be the most basic version that doessetTimeout
and delta-calculation itself; meanwhile it runs a feature-detect on arequestAnimationFrame
to see what kind of argument it provides. The alternatives allowed for are (1) standard epoch-Date
-based timestamp and (2)performance.now()
-based timestamp. If it finds anrAF
that works like this, it replacesframe
with an appropriaterAF
-based alternative.This should be pretty future-proof as the fallback should always work. However there may be a need to enhance it in future. e.g. if Mozilla's
animationStartTime
gets traction or if other browsers start usingperformance.now()
-based timestamps and vendor-prefixnow
(note though that that won't break this implementation, they'll just fall back to the basic implementation).I've also imported Bonzo's .jshintrc and I've added a test to ensure that
duration
is roughly obeyed, this should help detect shortcutting.