Merge pull request #253 from zzmp/fix-redraw-infinite-delay
Fix redraw infinite delay
This commit is contained in:
commit
be9032eb8f
3 changed files with 17 additions and 6 deletions
15
mithril.js
15
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()
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue