fix out-of-order issue when mixing new and old elements
This commit is contained in:
parent
08dd1cd62d
commit
b972607c8d
8 changed files with 64 additions and 22 deletions
12
mithril.js
12
mithril.js
|
|
@ -32,7 +32,7 @@ new function(window) {
|
|||
}
|
||||
return cell
|
||||
}
|
||||
function build(parent, data, cached, shouldReattach) {
|
||||
function build(parent, data, cached, shouldReattach, index) {
|
||||
if (data === null || data === undefined) {
|
||||
if (cached) clear(cached.nodes)
|
||||
return
|
||||
|
|
@ -49,7 +49,7 @@ new function(window) {
|
|||
if (dataType == "[object Array]") {
|
||||
var nodes = [], intact = cached.length === data.length
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var item = build(parent, data[i], cached[i], shouldReattach)
|
||||
var item = build(parent, data[i], cached[i], shouldReattach, i)
|
||||
if (item === undefined) continue
|
||||
if (!item.nodes.intact) intact = false
|
||||
cached[i] = item
|
||||
|
|
@ -70,14 +70,14 @@ new function(window) {
|
|||
if (isNew) {
|
||||
node = window.document.createElement(data.tag)
|
||||
cached = {tag: data.tag, attrs: setAttributes(node, data.attrs, {}), children: build(node, data.children, cached.children, true), nodes: [node]}
|
||||
parent.appendChild(node)
|
||||
parent.insertBefore(node, parent.childNodes[index])
|
||||
}
|
||||
else {
|
||||
node = cached.nodes[0]
|
||||
setAttributes(node, data.attrs, cached.attrs)
|
||||
cached.children = build(node, data.children, cached.children, false)
|
||||
cached.nodes.intact = true
|
||||
if (shouldReattach === true) parent.appendChild(node)
|
||||
if (shouldReattach === true) parent.insertBefore(node, parent.childNodes[index])
|
||||
}
|
||||
if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew)
|
||||
}
|
||||
|
|
@ -91,7 +91,7 @@ new function(window) {
|
|||
}
|
||||
else {
|
||||
node = window.document.createTextNode(data)
|
||||
parent.appendChild(node)
|
||||
parent.insertBefore(node, parent.childNodes[index])
|
||||
}
|
||||
cached = "string number boolean".indexOf(typeof data) > -1 ? new data.constructor(data) : data
|
||||
cached.nodes = [node]
|
||||
|
|
@ -110,7 +110,7 @@ new function(window) {
|
|||
}
|
||||
else {
|
||||
node = cached.nodes[0]
|
||||
parent.appendChild(node)
|
||||
parent.insertBefore(node, parent.childNodes[index])
|
||||
node.nodeValue = data
|
||||
}
|
||||
cached = new data.constructor(data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue