#424 fix key association when DOM is modified by external code
This commit is contained in:
parent
aacc618dfd
commit
496d820ee3
3 changed files with 27 additions and 6 deletions
|
|
@ -5,11 +5,15 @@
|
||||||
### News:
|
### News:
|
||||||
|
|
||||||
- Calling m.module without a module now unloads the current one [#420](https://github.com/lhorie/mithril.js/issues/420)
|
- Calling m.module without a module now unloads the current one [#420](https://github.com/lhorie/mithril.js/issues/420)
|
||||||
|
- Both `controller` and `view` properties in modules are now optional
|
||||||
|
|
||||||
### Bug Fixes:
|
### Bug Fixes:
|
||||||
|
|
||||||
- prevent empty class attributes [#382](https://github.com/lhorie/mithril.js/issues/382)
|
- prevent empty class attributes [#382](https://github.com/lhorie/mithril.js/issues/382)
|
||||||
- array-to-querystring serialization in `m.request` now behaves like jQuery [#426](https://github.com/lhorie/mithril.js/issues/426)
|
- array-to-querystring serialization in `m.request` now behaves like jQuery [#426](https://github.com/lhorie/mithril.js/issues/426)
|
||||||
|
- fix querystring detection bug in pathname mode [#425](https://github.com/lhorie/mithril.js/issues/425)
|
||||||
|
- don't add history entry if reloading from a link [#428](https://github.com/lhorie/mithril.js/issues/428)
|
||||||
|
- fix key association when DOM order is modified by external code [#424](https://github.com/lhorie/mithril.js/issues/424)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
14
mithril.js
14
mithril.js
|
|
@ -133,7 +133,7 @@ var m = (function app(window, undefined) {
|
||||||
for (var i = 0; i < cached.length; i++) {
|
for (var i = 0; i < cached.length; i++) {
|
||||||
if (cached[i] && cached[i].attrs && cached[i].attrs.key != null) {
|
if (cached[i] && cached[i].attrs && cached[i].attrs.key != null) {
|
||||||
shouldMaintainIdentities = true;
|
shouldMaintainIdentities = true;
|
||||||
existing[cached[i].attrs.key] = {action: DELETION, index: i}
|
existing[cached[i].attrs.key] = {action: DELETION, index: i, element: cached[i].nodes[0]}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (shouldMaintainIdentities) {
|
if (shouldMaintainIdentities) {
|
||||||
|
|
@ -154,11 +154,13 @@ var m = (function app(window, undefined) {
|
||||||
if (data[i].attrs.key != null) {
|
if (data[i].attrs.key != null) {
|
||||||
var key = data[i].attrs.key;
|
var key = data[i].attrs.key;
|
||||||
if (!existing[key]) existing[key] = {action: INSERTION, index: i};
|
if (!existing[key]) existing[key] = {action: INSERTION, index: i};
|
||||||
else existing[key] = {
|
else {
|
||||||
action: MOVE,
|
existing[key] = {
|
||||||
index: i,
|
action: MOVE,
|
||||||
from: existing[key].index,
|
index: i,
|
||||||
element: parentElement.childNodes[existing[key].index] || $document.createElement("div")
|
from: existing[key].index,
|
||||||
|
element: existing[key].element || $document.createElement("div")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else unkeyed.push({index: i, element: parentElement.childNodes[i] || $document.createElement("div")})
|
else unkeyed.push({index: i, element: parentElement.childNodes[i] || $document.createElement("div")})
|
||||||
|
|
|
||||||
|
|
@ -828,6 +828,21 @@ function testMithril(mock) {
|
||||||
m.render(root, m("div", [console.log()])) //don't throw in Firefox
|
m.render(root, m("div", [console.log()])) //don't throw in Firefox
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
var root = mock.document.createElement("div")
|
||||||
|
m.render(root, [
|
||||||
|
m("#div-1", {key: 1}),
|
||||||
|
m("#div-2", {key: 2}),
|
||||||
|
m("#div-3", {key: 3})
|
||||||
|
])
|
||||||
|
root.appendChild(root.childNodes[1])
|
||||||
|
m.render(root, [
|
||||||
|
m("#div-1", {key: 1}),
|
||||||
|
m("#div-3", {key: 3}),
|
||||||
|
m("#div-2", {key: 2})
|
||||||
|
])
|
||||||
|
return root.childNodes.map(function(node) {return node.id}).join() == "div-1,div-3,div-2"
|
||||||
|
})
|
||||||
//end m.render
|
//end m.render
|
||||||
|
|
||||||
//m.redraw
|
//m.redraw
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue