#299 fix key bug when nulls are mixed in

This commit is contained in:
Leo Horie 2014-12-08 09:55:32 -05:00
parent 8c30b1a554
commit dc42632e5a
3 changed files with 10 additions and 1 deletions

View file

@ -134,6 +134,7 @@ var m = (function app(window, undefined) {
}
}
if (shouldMaintainIdentities) {
if (data.indexOf(null) > -1) data = data.filter(function(x) {return x != null})
for (var i = 0; i < data.length; i++) {
if (data[i] && data[i].attrs) {
if (data[i].attrs.key != null) {

View file

@ -1,5 +1,5 @@
<!doctype html>
<script src="http://polyfill.io"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.0.3/es5-shim.min.js"></script>
<script src="test.js"></script>
<script src="mock.js"></script>
<script src="../mithril.js"></script>

View file

@ -780,6 +780,14 @@ function testMithril(mock) {
m.render(root, {foo: 123})
return root.childNodes.length == 0
})
test(function() {
//https://github.com/lhorie/mithril.js/issues/299
var root = mock.document.createElement("div")
m.render(root, m("div", [m("div", {key: 1}, 1), m("div", {key: 2}, 2), m("div", {key: 3}, 3), m("div", {key: 4}, 4), m("div", {key: 5}, 5), null, null, null, null, null, null, null, null, null, null]))
m.render(root, m("div", [null, null, m("div", {key: 3}, 3), null, null, m("div", {key: 6}, 6), null, null, m("div", {key: 9}, 9), null, null, m("div", {key: 12}, 12), null, null, m("div", {key: 15}, 15)]))
m.render(root, m("div", [m("div", {key: 1}, 1), m("div", {key: 2}, 2), m("div", {key: 3}, 3), m("div", {key: 4}, 4), m("div", {key: 5}, 5), null, null, null, null, null, null, null, null, null, null]))
return root.childNodes[0].childNodes.map(function(c) {return c.childNodes ? c.childNodes[0].nodeValue: c.nodeValue}).slice(0, 5).join("") == "12345"
})
//end m.render
//m.redraw