fix ordering bug when mixing arrays with virtual elements
This commit is contained in:
parent
12256290a9
commit
70496946cf
61 changed files with 6872 additions and 8 deletions
19
mithril.js
19
mithril.js
|
|
@ -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, i, namespace)
|
||||
var item = build(parent, data[i], cached[i], shouldReattach, index + i || i, namespace)
|
||||
if (item === undefined) continue
|
||||
if (!item.nodes.intact) intact = false
|
||||
cached[i] = item
|
||||
|
|
@ -73,17 +73,17 @@ new function(window) {
|
|||
cached = {
|
||||
tag: data.tag,
|
||||
attrs: setAttributes(node, data.attrs, {}, namespace),
|
||||
children: build(node, data.children, cached.children, true, undefined, namespace),
|
||||
children: build(node, data.children, cached.children, true, index, namespace),
|
||||
nodes: [node]
|
||||
}
|
||||
parent.insertBefore(node, parent.childNodes[index])
|
||||
parent.insertBefore(node, index !== undefined ? parent.childNodes[index] : null)
|
||||
}
|
||||
else {
|
||||
node = cached.nodes[0]
|
||||
setAttributes(node, data.attrs, cached.attrs, namespace)
|
||||
cached.children = build(node, data.children, cached.children, false, undefined, namespace)
|
||||
cached.children = build(node, data.children, cached.children, false, index, namespace)
|
||||
cached.nodes.intact = true
|
||||
if (shouldReattach === true) parent.insertBefore(node, parent.childNodes[index])
|
||||
if (shouldReattach === true) parent.insertBefore(node, index !== undefined ? parent.childNodes[index] : null)
|
||||
}
|
||||
if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew)
|
||||
}
|
||||
|
|
@ -97,7 +97,9 @@ new function(window) {
|
|||
}
|
||||
else {
|
||||
node = window.document.createTextNode(data)
|
||||
parent.insertBefore(node, parent.childNodes[index])
|
||||
console.log(555, node, index, parent.childNodes)
|
||||
parent.insertBefore(node, index !== undefined ? parent.childNodes[index] : null)
|
||||
console.log(666,parent.childNodes)
|
||||
}
|
||||
cached = "string number boolean".indexOf(typeof data) > -1 ? new data.constructor(data) : data
|
||||
cached.nodes = [node]
|
||||
|
|
@ -116,7 +118,7 @@ new function(window) {
|
|||
}
|
||||
else {
|
||||
node = cached.nodes[0]
|
||||
parent.insertBefore(node, parent.childNodes[index])
|
||||
parent.insertBefore(node, index !== undefined ? parent.childNodes[index] : null)
|
||||
node.nodeValue = data
|
||||
}
|
||||
cached = new data.constructor(data)
|
||||
|
|
@ -184,6 +186,9 @@ new function(window) {
|
|||
if (window.document.documentElement !== html) {
|
||||
window.document.replaceChild(html, window.document.documentElement)
|
||||
}
|
||||
},
|
||||
insertBefore: function(node, reference) {
|
||||
this.appendChild(node)
|
||||
}
|
||||
}
|
||||
var nodeCache = [], cellCache = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue