added optional param to m.redraw() to allow forced update
This commit is contained in:
parent
d567de08a8
commit
774be35cc2
3 changed files with 42 additions and 4 deletions
|
|
@ -406,10 +406,10 @@ Mithril = m = new function app(window, undefined) {
|
||||||
m.endComputation()
|
m.endComputation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.redraw = function() {
|
m.redraw = function(force) {
|
||||||
var cancel = window.cancelAnimationFrame || window.clearTimeout
|
var cancel = window.cancelAnimationFrame || window.clearTimeout
|
||||||
var defer = window.requestAnimationFrame || window.setTimeout
|
var defer = window.requestAnimationFrame || window.setTimeout
|
||||||
if (lastRedrawId) {
|
if (lastRedrawId && !force) {
|
||||||
cancel(lastRedrawId)
|
cancel(lastRedrawId)
|
||||||
lastRedrawId = defer(redraw, 0)
|
lastRedrawId = defer(redraw, 0)
|
||||||
}
|
}
|
||||||
|
|
@ -1740,6 +1740,25 @@ function testMithril(mock) {
|
||||||
mock.requestAnimationFrame.$resolve() //teardown
|
mock.requestAnimationFrame.$resolve() //teardown
|
||||||
return count === 3
|
return count === 3
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
mock.requestAnimationFrame.$resolve() //setup
|
||||||
|
var count = 0
|
||||||
|
var root = mock.document.createElement("div")
|
||||||
|
m.module(root, {
|
||||||
|
controller: function() {},
|
||||||
|
view: function(ctrl) {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
})
|
||||||
|
mock.requestAnimationFrame.$resolve() //teardown
|
||||||
|
m.redraw(true) //should run synchronously
|
||||||
|
|
||||||
|
m.redraw(true) //forced to run synchronously
|
||||||
|
m.redraw(true)
|
||||||
|
m.redraw(true)
|
||||||
|
mock.requestAnimationFrame.$resolve() //teardown
|
||||||
|
return count === 5
|
||||||
|
})
|
||||||
|
|
||||||
//m.route
|
//m.route
|
||||||
test(function() {
|
test(function() {
|
||||||
|
|
|
||||||
|
|
@ -406,10 +406,10 @@ Mithril = m = new function app(window, undefined) {
|
||||||
m.endComputation()
|
m.endComputation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.redraw = function() {
|
m.redraw = function(force) {
|
||||||
var cancel = window.cancelAnimationFrame || window.clearTimeout
|
var cancel = window.cancelAnimationFrame || window.clearTimeout
|
||||||
var defer = window.requestAnimationFrame || window.setTimeout
|
var defer = window.requestAnimationFrame || window.setTimeout
|
||||||
if (lastRedrawId) {
|
if (lastRedrawId && !force) {
|
||||||
cancel(lastRedrawId)
|
cancel(lastRedrawId)
|
||||||
lastRedrawId = defer(redraw, 0)
|
lastRedrawId = defer(redraw, 0)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -743,6 +743,25 @@ function testMithril(mock) {
|
||||||
mock.requestAnimationFrame.$resolve() //teardown
|
mock.requestAnimationFrame.$resolve() //teardown
|
||||||
return count === 3
|
return count === 3
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
mock.requestAnimationFrame.$resolve() //setup
|
||||||
|
var count = 0
|
||||||
|
var root = mock.document.createElement("div")
|
||||||
|
m.module(root, {
|
||||||
|
controller: function() {},
|
||||||
|
view: function(ctrl) {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
})
|
||||||
|
mock.requestAnimationFrame.$resolve() //teardown
|
||||||
|
m.redraw(true) //should run synchronously
|
||||||
|
|
||||||
|
m.redraw(true) //forced to run synchronously
|
||||||
|
m.redraw(true)
|
||||||
|
m.redraw(true)
|
||||||
|
mock.requestAnimationFrame.$resolve() //teardown
|
||||||
|
return count === 5
|
||||||
|
})
|
||||||
|
|
||||||
//m.route
|
//m.route
|
||||||
test(function() {
|
test(function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue