add {subtree: "retain"} flag to allow skipping diff from app space
This commit is contained in:
parent
c4494bf2ce
commit
fcf77dfa44
12 changed files with 169 additions and 11 deletions
|
|
@ -33,7 +33,11 @@ new function(window) {
|
|||
return cell
|
||||
}
|
||||
function build(parent, data, cached) {
|
||||
if (data === null || data === undefined) return
|
||||
if (data === null || data === undefined) {
|
||||
if (cached) clear(cached.nodes)
|
||||
return
|
||||
}
|
||||
if (data.subtree === "retain") return
|
||||
|
||||
var cachedType = type.call(cached), dataType = type.call(data)
|
||||
if (cachedType != dataType) {
|
||||
|
|
@ -59,8 +63,8 @@ new function(window) {
|
|||
}
|
||||
}
|
||||
else if (dataType == "[object Object]") {
|
||||
if (typeof data.tag != "string") return
|
||||
if (data.tag != cached.tag || Object.keys(data.attrs).join() != Object.keys(cached.attrs).join()) clear(cached.nodes)
|
||||
if (typeof data.tag != "string") return
|
||||
|
||||
var node, isNew = cached.nodes.length === 0
|
||||
if (isNew) {
|
||||
|
|
@ -640,6 +644,36 @@ function testMithril(mock) {
|
|||
m.render(root, m("div", [m("a", {href: "/second"})]))
|
||||
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", [m("li"), undefined]))
|
||||
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 === 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.length === 0
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("ul", [m("li")]))
|
||||
m.render(root, m("ul", [{}]))
|
||||
return root.childNodes[0].childNodes.length === 0
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("ul", [m("li", [m("a")])]))
|
||||
m.render(root, m("ul", [{subtree: "retain"}]))
|
||||
return root.childNodes[0].childNodes[0].childNodes[0].nodeName === "A"
|
||||
})
|
||||
|
||||
//m.redraw
|
||||
test(function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue