fix diff when changing from element to empty array
This commit is contained in:
parent
422ff19d18
commit
0354a4e251
2 changed files with 11 additions and 6 deletions
10
mithril.js
10
mithril.js
|
|
@ -104,18 +104,16 @@ Mithril = m = new function app(window) {
|
||||||
var item = build(parentElement, parentTag, cached, index, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, editable, namespace, configs)
|
var item = build(parentElement, parentTag, cached, index, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, editable, namespace, configs)
|
||||||
if (item === undefined) continue
|
if (item === undefined) continue
|
||||||
if (!item.nodes.intact) intact = false
|
if (!item.nodes.intact) intact = false
|
||||||
subArrayCount += item instanceof Array ? item.length : 1
|
var isArray = item instanceof Array
|
||||||
|
subArrayCount += isArray ? item.length : 1
|
||||||
cached[cacheCount++] = item
|
cached[cacheCount++] = item
|
||||||
}
|
}
|
||||||
if (!intact) {
|
if (!intact) {
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (var i = 0; i < data.length; i++) {
|
||||||
if (cached[i] !== undefined) nodes = nodes.concat(cached[i].nodes)
|
if (cached[i] !== undefined) nodes = nodes.concat(cached[i].nodes)
|
||||||
}
|
}
|
||||||
for (var i = nodes.length, node; node = cached.nodes[i]; i++) {
|
for (var i = 0, node; node = cached.nodes[i]; i++) {
|
||||||
if (node.parentNode !== null && node.parentNode.childNodes.length != nodes.length) {
|
if (node.parentNode !== null && nodes.indexOf(node) < 0) node.parentNode.removeChild(node)
|
||||||
node.parentNode.removeChild(node)
|
|
||||||
if (cached[i]) unload(cached[i])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (var i = cached.nodes.length, node; node = nodes[i]; i++) {
|
for (var i = cached.nodes.length, node; node = nodes[i]; i++) {
|
||||||
if (node.parentNode === null) parentElement.appendChild(node)
|
if (node.parentNode === null) parentElement.appendChild(node)
|
||||||
|
|
|
||||||
|
|
@ -660,6 +660,13 @@ function testMithril(mock) {
|
||||||
m.render(root, m("main", {config: configParent}, m("b", {config: configChild})))
|
m.render(root, m("main", {config: configParent}, m("b", {config: configChild})))
|
||||||
return unloadedParent === 1 && unloadedChild === 1
|
return unloadedParent === 1 && unloadedChild === 1
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
//https://github.com/lhorie/mithril.js/issues/150
|
||||||
|
var root = mock.document.createElement("div")
|
||||||
|
m.render(root, [m("a"), m("div")])
|
||||||
|
m.render(root, [[], m("div")])
|
||||||
|
return root.childNodes.length == 1 && root.childNodes[0].nodeName == "DIV"
|
||||||
|
})
|
||||||
//end m.render
|
//end m.render
|
||||||
|
|
||||||
//m.redraw
|
//m.redraw
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue