fix wrongful cache node clearing

This commit is contained in:
Leo Horie 2014-06-17 22:40:07 -04:00
parent 6d53b8429d
commit 0d44df0683
2 changed files with 23 additions and 1 deletions

View file

@ -160,6 +160,7 @@ Mithril = m = new function app(window) {
cached.nodes = [node]
}
else if (cached.valueOf() !== data.valueOf() || shouldReattach === true) {
node = cached.nodes[0]
if (!editable || editable !== window.document.activeElement) {
if (data.$trusted) {
var current = cached.nodes[0], nodes = [current]
@ -171,7 +172,6 @@ Mithril = m = new function app(window) {
else parentElement.innerHTML = data
}
else {
node = cached.nodes[0]
if (parentTag === "textarea") parentElement.value = data
else if (editable) editable.innerHTML = data
else {

View file

@ -548,6 +548,28 @@ function testMithril(mock) {
var fourthAfter = root.childNodes[0]
return firstBefore === firstAfter && secondBefore === secondAfter && fourthBefore === fourthAfter && root.childNodes[1].key == "10" && root.childNodes.length === 4
})
test(function() {
//https://github.com/lhorie/mithril.js/issues/98
var root = mock.document.createElement("div")
m.render(root, [m("a", {key: 1}), m("a", {key: 2}), m("a", {key: 3}), m("a", {key: 4}), m("a", {key: 5})])
var firstBefore = root.childNodes[0]
var secondBefore = root.childNodes[1]
var fourthBefore = root.childNodes[3]
m.render(root, [m("a", {key: 4}), m("a", {key: 10}), m("a", {key: 2}), m("a", {key: 1}), m("a", {key: 6}), m("a", {key: 7})])
var firstAfter = root.childNodes[3]
var secondAfter = root.childNodes[2]
var fourthAfter = root.childNodes[0]
return firstBefore === firstAfter && secondBefore === secondAfter && fourthBefore === fourthAfter && root.childNodes[1].key == "10" && root.childNodes[4].key == "6" && root.childNodes[5].key == "7" && root.childNodes.length === 6
})
test(function() {
//https://github.com/lhorie/mithril.js/issues/134
var root = mock.document.createElement("div")
m.render(root, m("div", {contenteditable: true}, "test"))
mock.document.activeElement = root.childNodes[0]
m.render(root, m("div", {contenteditable: true}, "test1"))
m.render(root, m("div", {contenteditable: false}, "test2"))
return root.childNodes[0].childNodes[0].nodeValue === "test2"
})
//end m.render
//m.redraw