diff --git a/mithril.js b/mithril.js index ef2db7e4..24cc7581 100644 --- a/mithril.js +++ b/mithril.js @@ -439,7 +439,7 @@ Mithril = m = new function app(window, undefined) { return _prop(store) } - var roots = [], modules = [], controllers = [], lastRedrawId = 0, computePostRedrawHook = null, prevented = false + var roots = [], modules = [], controllers = [], lastRedrawId = 0, redrawAgain = false, computePostRedrawHook = null, prevented = false m.module = function(root, module) { var index = roots.indexOf(root) if (index < 0) index = roots.length @@ -464,12 +464,19 @@ Mithril = m = new function app(window, undefined) { var cancel = window.cancelAnimationFrame || window.clearTimeout var defer = window.requestAnimationFrame || window.setTimeout if (lastRedrawId && force !== true) { - cancel(lastRedrawId) - lastRedrawId = defer(redraw, 16) //60 frames per second = 1 call per 16 ms + redrawAgain = true } else { redraw() - lastRedrawId = defer(function() {lastRedrawId = null}, 16) + lastRedrawId = defer(delay, 16) //60 frames per second = 1 call per 16 ms + } + + function delay() { + lastRedrawId = null + if (redrawAgain) { + redrawAgain = false + m.redraw() + } } } m.redraw.strategy = m.prop() diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 32a1b704..a6e9b42e 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1454,6 +1454,7 @@ function testMithril(mock) { } }) root.childNodes[0].onclick({}) + mock.requestAnimationFrame.$resolve() //teardown return strategy == "diff" && root.childNodes[0].childNodes[0].nodeValue == "1" }) test(function() { diff --git a/tests/mock.js b/tests/mock.js index 5629dbce..4cd2633f 100644 --- a/tests/mock.js +++ b/tests/mock.js @@ -93,8 +93,11 @@ mock.window = new function() { } window.requestAnimationFrame.$id = 1 window.requestAnimationFrame.$resolve = function() { - if (window.requestAnimationFrame.$callback) window.requestAnimationFrame.$callback() - window.requestAnimationFrame.$callback = null + if (window.requestAnimationFrame.$callback) { + var callback = window.requestAnimationFrame.$callback + window.requestAnimationFrame.$callback = null + callback() + } } window.XMLHttpRequest = new function() { var request = function() {