added optional param to m.redraw() to allow forced update

This commit is contained in:
Zolmeister 2014-08-13 12:59:03 -07:00
parent d567de08a8
commit 774be35cc2
3 changed files with 42 additions and 4 deletions

View file

@ -406,10 +406,10 @@ Mithril = m = new function app(window, undefined) {
m.endComputation()
}
}
m.redraw = function() {
m.redraw = function(force) {
var cancel = window.cancelAnimationFrame || window.clearTimeout
var defer = window.requestAnimationFrame || window.setTimeout
if (lastRedrawId) {
if (lastRedrawId && !force) {
cancel(lastRedrawId)
lastRedrawId = defer(redraw, 0)
}
@ -1740,6 +1740,25 @@ function testMithril(mock) {
mock.requestAnimationFrame.$resolve() //teardown
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
test(function() {

View file

@ -406,10 +406,10 @@ Mithril = m = new function app(window, undefined) {
m.endComputation()
}
}
m.redraw = function() {
m.redraw = function(force) {
var cancel = window.cancelAnimationFrame || window.clearTimeout
var defer = window.requestAnimationFrame || window.setTimeout
if (lastRedrawId) {
if (lastRedrawId && !force) {
cancel(lastRedrawId)
lastRedrawId = defer(redraw, 0)
}

View file

@ -743,6 +743,25 @@ function testMithril(mock) {
mock.requestAnimationFrame.$resolve() //teardown
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
test(function() {