#551 don't destroy root if forced synchronous redraw

This commit is contained in:
Leo Horie 2015-04-13 23:04:04 -04:00
parent 4d03595bb1
commit f0f1e88170
2 changed files with 74 additions and 1 deletions

View file

@ -241,7 +241,7 @@ var m = (function app(window, undefined) {
var controllerIndex = cached.controllerConstructors ? cached.controllerConstructors.indexOf(controllerConstructor) : -1
var controller = controllerIndex > -1 ? cached.controllers[controllerIndex] : new (data.controller || function() {})
var key = data && data.attrs && data.attrs.key
data = pendingRequests == 0 ? data.view(controller) : {tag: "placeholder"}
data = pendingRequests == 0 || cached ? data.view(controller) : {tag: "placeholder"}
if (key) {
if (!data.attrs) data.attrs = {}
data.attrs.key = key

View file

@ -960,6 +960,79 @@ function testMithril(mock) {
return root.childNodes[0].nodeName == "DIV"
})
test(function() {
//https://github.com/lhorie/mithril.js/issues/551
var root = mock.document.createElement("div")
var a = false, found = false, unloaded = false
var Root = {
view: function() {
return Comp
}
}
var Comp = {
view: function() {
return m("div", {config: Comp.config}, [
m("div", {onclick: function() {
a = !a
m.redraw(true)
found = root.childNodes[0].childNodes[1]
}}, "asd"),
a ? m("#a", "aaa") : null,
"test"
])
},
config: function(el, init, ctx) {
if (!init) ctx.onunload = function() {
unloaded = true
}
}
}
m.mount(root, Root)
var target = root.childNodes[0].childNodes[0]
target.onclick({currentTarget: target})
mock.requestAnimationFrame.$resolve()
return !unloaded && found.id === "a"
})
test(function() {
//https://github.com/lhorie/mithril.js/issues/551
var root = mock.document.createElement("div")
var a = false, found = false, unloaded = false
var Root = {
view: function() {
return Comp
}
}
var Comp = {
view: function() {
return m("div", {config: Comp.config}, [
m("div", {onclick: function() {
a = !a
m.redraw(true)
found = root.childNodes[0].childNodes[1]
m.redraw.strategy("none")
}}, "asd"),
a ? m("#a", "aaa") : null,
"test"
])
},
config: function(el, init, ctx) {
if (!init) ctx.onunload = function() {
unloaded = true
}
}
}
m.mount(root, Root)
var target = root.childNodes[0].childNodes[0]
target.onclick({currentTarget: target})
mock.requestAnimationFrame.$resolve()
return !unloaded && found.id === "a"
})
m.redraw.strategy(undefined) //teardown for m.mount tests
//m.withAttr