fix key ordering in interpolation case
This commit is contained in:
parent
1e829f1657
commit
c8ce0d8dee
2 changed files with 9 additions and 2 deletions
|
|
@ -80,7 +80,7 @@ Mithril = m = new function app(window) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var actions = Object.keys(existing).map(function(key) {return existing[key]})
|
var actions = Object.keys(existing).map(function(key) {return existing[key]})
|
||||||
var changes = actions.sort(function(a, b) {return a.action - b.action || b.index - a.index})
|
var changes = actions.sort(function(a, b) {return a.action - b.action || a.index - b.index})
|
||||||
var newCached = cached.slice()
|
var newCached = cached.slice()
|
||||||
|
|
||||||
for (var i = 0, change; change = changes[i]; i++) {
|
for (var i = 0, change; change = changes[i]; i++) {
|
||||||
|
|
@ -90,7 +90,7 @@ Mithril = m = new function app(window) {
|
||||||
}
|
}
|
||||||
if (change.action == INSERTION) {
|
if (change.action == INSERTION) {
|
||||||
var dummy = window.document.createElement("div")
|
var dummy = window.document.createElement("div")
|
||||||
dummy.key = data[change.index].attrs.key.toString()
|
dummy.key = data[change.index].attrs.key
|
||||||
parentElement.insertBefore(dummy, parentElement.childNodes[change.index])
|
parentElement.insertBefore(dummy, parentElement.childNodes[change.index])
|
||||||
newCached.splice(change.index, 0, {attrs: {key: data[change.index].attrs.key}, nodes: [dummy]})
|
newCached.splice(change.index, 0, {attrs: {key: data[change.index].attrs.key}, nodes: [dummy]})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -678,6 +678,13 @@ function testMithril(mock) {
|
||||||
]))
|
]))
|
||||||
return root.childNodes[0].childNodes[8].nodeName == "SPAN"
|
return root.childNodes[0].childNodes[8].nodeName == "SPAN"
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
//https://github.com/lhorie/mithril.js/issues/157
|
||||||
|
var root = mock.document.createElement("div")
|
||||||
|
m.render(root, m("ul", [m("li", {key: 0}), m("li", {key: 2}), m("li", {key: 4})]))
|
||||||
|
m.render(root, m("ul", [m("li", {key: 0}), m("li", {key: 1}), m("li", {key: 2}), m("li", {key: 3}), m("li", {key: 4}), m("li", {key: 5})]))
|
||||||
|
return root.childNodes[0].childNodes.map(function(n) {return n.key}).join("") == "012345"
|
||||||
|
})
|
||||||
//end m.render
|
//end m.render
|
||||||
|
|
||||||
//m.redraw
|
//m.redraw
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue