refactor redraw

This commit is contained in:
Leo Horie 2014-07-21 22:08:37 -04:00
parent 0f5d051d4b
commit 7295b6e9e9
6 changed files with 26 additions and 9 deletions

View file

@ -284,7 +284,10 @@ Mithril = m = new function app(window) {
e = e || event
m.startComputation()
try {return callback.call(object, e)}
finally {m.endComputation()}
finally {
if (!lastRedrawId) lastRedrawId = -1;
m.endComputation()
}
}
}
@ -351,8 +354,14 @@ Mithril = m = new function app(window) {
m.redraw = function() {
var cancel = window.cancelAnimationFrame || window.clearTimeout
var defer = window.requestAnimationFrame || window.setTimeout
cancel(lastRedrawId)
lastRedrawId = defer(redraw, 0)
if (lastRedrawId) {
cancel(lastRedrawId)
lastRedrawId = defer(redraw, 0)
}
else {
redraw()
lastRedrawId = defer(function() {lastRedrawId = null}, 0)
}
}
function redraw() {
for (var i = 0; i < roots.length; i++) {
@ -362,6 +371,7 @@ Mithril = m = new function app(window) {
computePostRedrawHook()
computePostRedrawHook = null
}
lastRedrawId = null
}
var pendingRequests = 0