fix ordering bug when mixing arrays with virtual elements

This commit is contained in:
Leo Horie 2014-04-11 15:23:22 -04:00
parent 12256290a9
commit 70496946cf
61 changed files with 6872 additions and 8 deletions

View file

@ -186,6 +186,7 @@ function testMithril(mock) {
var root = mock.document.createElement("div")
m.render(root, m("#foo", [null, m("#bar")]))
m.render(root, m("#foo", ["test", m("#bar")]))
console.log(111,root.childNodes[0].childNodes[0])
return root.childNodes[0].childNodes[0].nodeValue === "test"
})
test(function() {
@ -200,6 +201,7 @@ function testMithril(mock) {
var root = mock.document.createElement("div")
m.render(root, m("#foo", ["test", m("#bar")]))
m.render(root, m("#foo", [m("div"), m("#bar")]))
console.log(111,root.childNodes[0].childNodes[0])
return root.childNodes[0].childNodes[0].nodeName === "DIV"
})
test(function() {
@ -207,8 +209,25 @@ function testMithril(mock) {
var root = mock.document.createElement("div")
m.render(root, m("#foo", [m("div"), m("#bar")]))
m.render(root, m("#foo", ["test", m("#bar")]))
console.log(123,root.childNodes[0].childNodes[0])
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", [m("#bar")]))
m.render(root, m("#foo", [m("#bar"), [m("#baz")]]))
console.log(113,root.childNodes[0].childNodes[1])
return root.childNodes[0].childNodes[1].id === "baz"
})
test(function() {
//https://github.com/lhorie/mithril.js/issues/48
var root = mock.document
m.render(root, m("html", [m("#foo")]))
var result = root.childNodes[0].childNodes[0].id === "foo"
root.childNodes = [mock.document.createElement("html")]
return result
})
//m.redraw
test(function() {

View file

@ -36,7 +36,7 @@ mock.window = new function() {
window.document.createTextNode = function(text) {
return {nodeValue: text.toString()}
}
window.document.documentElement = null
window.document.documentElement = window.document.createElement("html")
window.document.replaceChild = function(newChild, oldChild) {
var index = this.childNodes.indexOf(oldChild)
if (index > -1) this.childNodes.splice(index, 1, newChild)