diff --git a/mithril.js b/mithril.js index c7d17711..c2326590 100644 --- a/mithril.js +++ b/mithril.js @@ -460,14 +460,15 @@ Mithril = m = new function app(window, undefined) { m.redraw = function(force) { var cancel = window.cancelAnimationFrame || window.clearTimeout var defer = window.requestAnimationFrame || window.setTimeout + var delay = new Date - lastRedrawCallTime //lastRedrawId is a positive number if a second redraw is requested before the next animation frame //lastRedrawId is -1 if the redraw is the first one in a event handler (see #151) //lastRedrawID is null if it's the first redraw and not an event handler if (lastRedrawId && force !== true) { //when setTimeout: only reschedule redraw if time between now and previous redraw is bigger than a frame, otherwise keep currently scheduled timeout //when rAF: always reschedule redraw - if (new Date - lastRedrawCallTime > FRAME_BUDGET || defer == window.requestAnimationFrame) { - if (lastRedrawID > 0) cancel(lastRedrawId) + if (delay > FRAME_BUDGET || defer == window.requestAnimationFrame) { + if (lastRedrawId > 0) cancel(lastRedrawId) lastRedrawId = defer(redraw, delay) } }