fix out-of-order issue when mixing new and old elements

This commit is contained in:
Leo Horie 2014-04-09 09:12:14 -04:00
parent 08dd1cd62d
commit b972607c8d
8 changed files with 64 additions and 22 deletions

View file

@ -142,13 +142,14 @@ function testMithril(mock) {
return root.childNodes[0].childNodes[0].childNodes[0].nodeName === "A"
})
test(function() {
//https://github.com/lhorie/mithril.js/issues/43
var root = mock.document.createElement("div")
m.render(root, m("a", {config: m.route}, "test"))
m.render(root, m("a", {config: m.route}, "test"))
return root.childNodes[0].childNodes[0].nodeValue === "test"
})
test(function() {
//see issue #29
//https://github.com/lhorie/mithril.js/issues/29
var root = mock.document.createElement("div")
var list = [false, false]
m.render(root, list.reverse().map(function(flag, index) {
@ -167,6 +168,20 @@ function testMithril(mock) {
return root.childNodes[0].checked === false && root.childNodes[1].checked === true
})
test(function() {
//https://github.com/lhorie/mithril.js/issues/44
var root = mock.document.createElement("div")
m.render(root, m("#foo", [null, m("#bar")]))
m.render(root, m("#foo", ["test", m("#bar")]))
return root.childNodes[0].childNodes[0].nodeValue === "test"
})
test(function() {
//https://github.com/lhorie/mithril.js/issues/44
var root = mock.document.createElement("div")
m.render(root, m("#foo", [null, m("#bar")]))
m.render(root, m("#foo", [m("div"), m("#bar")]))
return root.childNodes[0].childNodes[0].nodeName === "DIV"
})
//m.redraw
test(function() {

View file

@ -10,6 +10,12 @@ mock.window = new function() {
appendChild: window.document.appendChild,
removeChild: window.document.removeChild,
replaceChild: window.document.replaceChild,
insertBefore: function(node, reference) {
node.parentNode = this
var index = this.childNodes.indexOf(reference)
if (index < 0) this.childNodes.push(node)
else this.childNodes.splice(index, 0, node)
},
setAttribute: function(name, value) {
this[name] = value.toString()
},