#524 fix diff bug when mixing undefined in a tree
This commit is contained in:
parent
b6c2f70526
commit
648f4734b5
2 changed files with 42 additions and 12 deletions
|
|
@ -138,13 +138,15 @@ var m = (function app(window, undefined) {
|
|||
existing[cached[i].attrs.key] = {action: DELETION, index: i}
|
||||
}
|
||||
}
|
||||
|
||||
data = data.filter(function(x) {return x != null})
|
||||
|
||||
var guid = 0
|
||||
for (var i = 0, len = data.length; i < len; i++) {
|
||||
if (data[i] && data[i].attrs && data[i].attrs.key == null) data[i].attrs.key = "__mithril__" + guid++
|
||||
}
|
||||
|
||||
if (shouldMaintainIdentities) {
|
||||
if (data.indexOf(null) > -1) data = data.filter(function(x) {return x != null})
|
||||
|
||||
var keysDiffer = false
|
||||
if (data.length != cached.length) keysDiffer = true
|
||||
else for (var i = 0, cachedCell, dataCell; cachedCell = cached[i], dataCell = data[i]; i++) {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,32 @@ function testMithril(mock) {
|
|||
test(function() {return m("div", [1], [2], [3]).children.length === 3})
|
||||
|
||||
//m.module
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
var whatever = 1
|
||||
var app = {
|
||||
view: function() {
|
||||
return [
|
||||
whatever % 2 ? m('span', '% 2') : undefined,
|
||||
m('div', 'bugs'),
|
||||
m('a'),
|
||||
]
|
||||
}
|
||||
}
|
||||
m.module(root, app)
|
||||
mock.requestAnimationFrame.$resolve()
|
||||
|
||||
whatever++
|
||||
m.redraw()
|
||||
mock.requestAnimationFrame.$resolve()
|
||||
|
||||
whatever++
|
||||
m.redraw()
|
||||
mock.requestAnimationFrame.$resolve()
|
||||
|
||||
return root.childNodes.length
|
||||
})
|
||||
|
||||
test(function() {
|
||||
mock.requestAnimationFrame.$resolve()
|
||||
|
||||
|
|
@ -219,7 +245,7 @@ function testMithril(mock) {
|
|||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("div", [undefined]))
|
||||
return root.childNodes[0].childNodes[0].nodeValue === ""
|
||||
return root.childNodes[0].childNodes.length === 0
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
|
|
@ -242,19 +268,19 @@ function testMithril(mock) {
|
|||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("ul", [m("li")]))
|
||||
m.render(root, m("ul", [m("li"), undefined]))
|
||||
return root.childNodes[0].childNodes[1].nodeValue === ""
|
||||
return root.childNodes[0].childNodes.length == 1
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("ul", [m("li"), m("li")]))
|
||||
m.render(root, m("ul", [m("li"), undefined]))
|
||||
return root.childNodes[0].childNodes.length == 2 && root.childNodes[0].childNodes[1].nodeValue === ""
|
||||
return root.childNodes[0].childNodes.length == 1
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("ul", [m("li")]))
|
||||
m.render(root, m("ul", [undefined]))
|
||||
return root.childNodes[0].childNodes[0].nodeValue === ""
|
||||
return root.childNodes[0].childNodes.length == 0
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
|
|
@ -437,18 +463,18 @@ function testMithril(mock) {
|
|||
m.render(root, m("div", [m("button"), m("ul")]))
|
||||
var valueBefore = root.childNodes[0].childNodes[0].nodeName
|
||||
m.render(root, m("div", [undefined, m("ul")]))
|
||||
var valueAfter = root.childNodes[0].childNodes[0].nodeValue
|
||||
return valueBefore === "BUTTON" && valueAfter === ""
|
||||
var valueAfter = root.childNodes[0].childNodes[0].nodeName
|
||||
return valueBefore === "BUTTON" && valueAfter === "UL"
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("div", [m("ul"), undefined]))
|
||||
var valueBefore1 = root.childNodes[0].childNodes[0].nodeName
|
||||
var valueBefore2 = root.childNodes[0].childNodes[1].nodeValue
|
||||
var valueBefore2 = root.childNodes[0].childNodes.length
|
||||
m.render(root, m("div", [undefined, m("ul")]))
|
||||
var valueAfter1 = root.childNodes[0].childNodes[0].nodeValue
|
||||
var valueAfter2 = root.childNodes[0].childNodes[1].nodeName
|
||||
return valueBefore1 === "UL" && valueAfter1 === "" && valueBefore2 === "" && valueAfter2 === "UL"
|
||||
var valueAfter1 = root.childNodes[0].childNodes[0].nodeName
|
||||
var valueAfter2 = root.childNodes[0].childNodes.length
|
||||
return valueBefore1 === "UL" && valueAfter1 === "UL" && valueBefore2 === 1 && valueAfter2 === 1
|
||||
})
|
||||
test(function() {
|
||||
//https://github.com/lhorie/mithril.js/issues/79
|
||||
|
|
@ -2782,6 +2808,8 @@ function testMithril(mock) {
|
|||
}
|
||||
|
||||
//mock
|
||||
var start = performance.now()
|
||||
testMithril(mock.window);
|
||||
console.log("test finished running in:", performance.now() - start, "ms")
|
||||
|
||||
test.print(function(value) {console.log(value)})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue