fix cloning when undefined present in tree
This commit is contained in:
parent
f28ae323c5
commit
3433cabf88
7 changed files with 59 additions and 26 deletions
|
|
@ -33,10 +33,7 @@ Mithril = m = new function app(window) {
|
|||
return cell
|
||||
}
|
||||
function build(parentElement, parentTag, data, cached, shouldReattach, index, editable, namespace) {
|
||||
if (data === null || data === undefined) {
|
||||
if (cached) clear(cached.nodes)
|
||||
return
|
||||
}
|
||||
if (data === null || data === undefined) data = ""
|
||||
if (data.subtree === "retain") return
|
||||
|
||||
var cachedType = type.call(cached), dataType = type.call(data)
|
||||
|
|
@ -56,7 +53,9 @@ Mithril = m = new function app(window) {
|
|||
cached[cacheCount++] = item
|
||||
}
|
||||
if (!intact) {
|
||||
//console.log(123, nodes, cached.nodes, 666,cached[0], cached[1], data.length)
|
||||
for (var i = 0; i < data.length; i++) if (cached[i] !== undefined) nodes = nodes.concat(cached[i].nodes)
|
||||
//console.log(234, nodes, cached.nodes, cached[i])
|
||||
for (var i = nodes.length, node; node = cached.nodes[i]; i++) if (node.parentNode !== null) node.parentNode.removeChild(node)
|
||||
for (var i = cached.nodes.length, node; node = nodes[i]; i++) if (node.parentNode === null) parentElement.appendChild(node)
|
||||
if (data.length < cached.length) cached.length = data.length
|
||||
|
|
@ -715,7 +714,7 @@ function testMithril(mock) {
|
|||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("div", [undefined]))
|
||||
return root.childNodes[0].childNodes.length === 0
|
||||
return root.childNodes[0].childNodes[0].nodeValue === ""
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
|
|
@ -738,19 +737,19 @@ function testMithril(mock) {
|
|||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("ul", [m("li")]))
|
||||
m.render(root, m("ul", [m("li"), undefined]))
|
||||
return root.childNodes[0].childNodes.length === 1
|
||||
return root.childNodes[0].childNodes[1].nodeValue === ""
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("ul", [m("li"), m("li")]))
|
||||
m.render(root, m("ul", [m("li"), undefined]))
|
||||
return root.childNodes[0].childNodes.length === 1
|
||||
return root.childNodes[0].childNodes[1].nodeValue === ""
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("ul", [m("li")]))
|
||||
m.render(root, m("ul", [undefined]))
|
||||
return root.childNodes[0].childNodes.length === 0
|
||||
return root.childNodes[0].childNodes[0].nodeValue === ""
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
|
|
@ -936,6 +935,24 @@ function testMithril(mock) {
|
|||
m.render(root, m("div", "foo"))
|
||||
return root.childNodes.length == 1
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("div", [m("button"), m("ul")]))
|
||||
var valueBefore = root.childNodes[0].childNodes[0].nodeName
|
||||
m.render(root, m("div", [undefined, m("ul")]))
|
||||
var valueAfter = root.childNodes[0].childNodes[0].nodeValue
|
||||
return valueBefore === "BUTTON" && valueAfter === ""
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("div", [m("ul"), undefined]))
|
||||
var valueBefore1 = root.childNodes[0].childNodes[0].nodeName
|
||||
var valueBefore2 = root.childNodes[0].childNodes[1].nodeValue
|
||||
m.render(root, m("div", [undefined, m("ul")]))
|
||||
var valueAfter1 = root.childNodes[0].childNodes[0].nodeValue
|
||||
var valueAfter2 = root.childNodes[0].childNodes[1].nodeName
|
||||
return valueBefore1 === "UL" && valueAfter1 === "" && valueBefore2 === "" && valueAfter2 === "UL"
|
||||
})
|
||||
//end m.render
|
||||
|
||||
//m.redraw
|
||||
|
|
@ -949,11 +966,11 @@ function testMithril(mock) {
|
|||
})
|
||||
controller.value = "foo"
|
||||
m.redraw()
|
||||
var lengthBefore = root.childNodes.length
|
||||
var valueBefore = root.childNodes[0].nodeValue
|
||||
mock.performance.$elapse(50)
|
||||
m.redraw()
|
||||
mock.performance.$elapse(50) //teardown
|
||||
return lengthBefore === 0 && root.childNodes[0].nodeValue === "foo"
|
||||
return valueBefore === "" && root.childNodes[0].nodeValue === "foo"
|
||||
})
|
||||
test(function() {
|
||||
mock.performance.$elapse(50) //setup
|
||||
|
|
|
|||
|
|
@ -33,10 +33,7 @@ Mithril = m = new function app(window) {
|
|||
return cell
|
||||
}
|
||||
function build(parentElement, parentTag, data, cached, shouldReattach, index, editable, namespace) {
|
||||
if (data === null || data === undefined) {
|
||||
if (cached) clear(cached.nodes)
|
||||
return
|
||||
}
|
||||
if (data === null || data === undefined) data = ""
|
||||
if (data.subtree === "retain") return
|
||||
|
||||
var cachedType = type.call(cached), dataType = type.call(data)
|
||||
|
|
@ -56,7 +53,9 @@ Mithril = m = new function app(window) {
|
|||
cached[cacheCount++] = item
|
||||
}
|
||||
if (!intact) {
|
||||
//console.log(123, nodes, cached.nodes, 666,cached[0], cached[1], data.length)
|
||||
for (var i = 0; i < data.length; i++) if (cached[i] !== undefined) nodes = nodes.concat(cached[i].nodes)
|
||||
//console.log(234, nodes, cached.nodes, cached[i])
|
||||
for (var i = nodes.length, node; node = cached.nodes[i]; i++) if (node.parentNode !== null) node.parentNode.removeChild(node)
|
||||
for (var i = cached.nodes.length, node; node = nodes[i]; i++) if (node.parentNode === null) parentElement.appendChild(node)
|
||||
if (data.length < cached.length) cached.length = data.length
|
||||
|
|
|
|||
2
archive/v0.1.11/mithril.min.js
vendored
2
archive/v0.1.11/mithril.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
|
|
@ -33,10 +33,7 @@ Mithril = m = new function app(window) {
|
|||
return cell
|
||||
}
|
||||
function build(parentElement, parentTag, data, cached, shouldReattach, index, editable, namespace) {
|
||||
if (data === null || data === undefined) {
|
||||
if (cached) clear(cached.nodes)
|
||||
return
|
||||
}
|
||||
if (data === null || data === undefined) data = ""
|
||||
if (data.subtree === "retain") return
|
||||
|
||||
var cachedType = type.call(cached), dataType = type.call(data)
|
||||
|
|
@ -56,7 +53,9 @@ Mithril = m = new function app(window) {
|
|||
cached[cacheCount++] = item
|
||||
}
|
||||
if (!intact) {
|
||||
//console.log(123, nodes, cached.nodes, 666,cached[0], cached[1], data.length)
|
||||
for (var i = 0; i < data.length; i++) if (cached[i] !== undefined) nodes = nodes.concat(cached[i].nodes)
|
||||
//console.log(234, nodes, cached.nodes, cached[i])
|
||||
for (var i = nodes.length, node; node = cached.nodes[i]; i++) if (node.parentNode !== null) node.parentNode.removeChild(node)
|
||||
for (var i = cached.nodes.length, node; node = nodes[i]; i++) if (node.parentNode === null) parentElement.appendChild(node)
|
||||
if (data.length < cached.length) cached.length = data.length
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ function testMithril(mock) {
|
|||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("div", [undefined]))
|
||||
return root.childNodes[0].childNodes.length === 0
|
||||
return root.childNodes[0].childNodes[0].nodeValue === ""
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
|
|
@ -128,19 +128,19 @@ function testMithril(mock) {
|
|||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("ul", [m("li")]))
|
||||
m.render(root, m("ul", [m("li"), undefined]))
|
||||
return root.childNodes[0].childNodes.length === 1
|
||||
return root.childNodes[0].childNodes[1].nodeValue === ""
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("ul", [m("li"), m("li")]))
|
||||
m.render(root, m("ul", [m("li"), undefined]))
|
||||
return root.childNodes[0].childNodes.length === 1
|
||||
return root.childNodes[0].childNodes[1].nodeValue === ""
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("ul", [m("li")]))
|
||||
m.render(root, m("ul", [undefined]))
|
||||
return root.childNodes[0].childNodes.length === 0
|
||||
return root.childNodes[0].childNodes[0].nodeValue === ""
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
|
|
@ -326,6 +326,24 @@ function testMithril(mock) {
|
|||
m.render(root, m("div", "foo"))
|
||||
return root.childNodes.length == 1
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("div", [m("button"), m("ul")]))
|
||||
var valueBefore = root.childNodes[0].childNodes[0].nodeName
|
||||
m.render(root, m("div", [undefined, m("ul")]))
|
||||
var valueAfter = root.childNodes[0].childNodes[0].nodeValue
|
||||
return valueBefore === "BUTTON" && valueAfter === ""
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("div", [m("ul"), undefined]))
|
||||
var valueBefore1 = root.childNodes[0].childNodes[0].nodeName
|
||||
var valueBefore2 = root.childNodes[0].childNodes[1].nodeValue
|
||||
m.render(root, m("div", [undefined, m("ul")]))
|
||||
var valueAfter1 = root.childNodes[0].childNodes[0].nodeValue
|
||||
var valueAfter2 = root.childNodes[0].childNodes[1].nodeName
|
||||
return valueBefore1 === "UL" && valueAfter1 === "" && valueBefore2 === "" && valueAfter2 === "UL"
|
||||
})
|
||||
//end m.render
|
||||
|
||||
//m.redraw
|
||||
|
|
@ -339,11 +357,11 @@ function testMithril(mock) {
|
|||
})
|
||||
controller.value = "foo"
|
||||
m.redraw()
|
||||
var lengthBefore = root.childNodes.length
|
||||
var valueBefore = root.childNodes[0].nodeValue
|
||||
mock.performance.$elapse(50)
|
||||
m.redraw()
|
||||
mock.performance.$elapse(50) //teardown
|
||||
return lengthBefore === 0 && root.childNodes[0].nodeValue === "foo"
|
||||
return valueBefore === "" && root.childNodes[0].nodeValue === "foo"
|
||||
})
|
||||
test(function() {
|
||||
mock.performance.$elapse(50) //setup
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue