From d14306a9ca630ade0074afdebe5a856f5cf89b92 Mon Sep 17 00:00:00 2001 From: zzmp Date: Wed, 17 Sep 2014 14:19:46 -0700 Subject: [PATCH 1/3] fix mock requestAnimationFrame to allow chaining --- tests/mock.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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() { From 7af59740f91c07d66f15b4b3aa5f68348fbe0ff8 Mon Sep 17 00:00:00 2001 From: zzmp Date: Wed, 17 Sep 2014 14:23:26 -0700 Subject: [PATCH 2/3] add teardown to test(L1457) --- tests/mithril-tests.js | 1 + 1 file changed, 1 insertion(+) 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() { From 8f3af0b6f1a39e81bc6c17a008182d6d73cfb41e Mon Sep 17 00:00:00 2001 From: zzmp Date: Wed, 17 Sep 2014 14:24:22 -0700 Subject: [PATCH 3/3] prevent infinite delay on redraw --- mithril.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mithril.js b/mithril.js index e729f399..5321bdb1 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()