don't touch DOM to check for parenthood
This commit is contained in:
parent
3f8c630702
commit
9dcffab2ac
6 changed files with 20 additions and 20 deletions
|
|
@ -32,7 +32,7 @@ new function(window) {
|
||||||
}
|
}
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
function build(parent, data, cached) {
|
function build(parent, data, cached, shouldReattach) {
|
||||||
if (data === null || data === undefined) {
|
if (data === null || data === undefined) {
|
||||||
if (cached) clear(cached.nodes)
|
if (cached) clear(cached.nodes)
|
||||||
return
|
return
|
||||||
|
|
@ -49,7 +49,7 @@ new function(window) {
|
||||||
if (dataType == "[object Array]") {
|
if (dataType == "[object Array]") {
|
||||||
var nodes = [], intact = cached.length === data.length
|
var nodes = [], intact = cached.length === data.length
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (var i = 0; i < data.length; i++) {
|
||||||
var item = build(parent, data[i], cached[i])
|
var item = build(parent, data[i], cached[i], shouldReattach)
|
||||||
if (item === undefined) continue
|
if (item === undefined) continue
|
||||||
if (!item.nodes.intact) intact = false
|
if (!item.nodes.intact) intact = false
|
||||||
cached[i] = item
|
cached[i] = item
|
||||||
|
|
@ -69,15 +69,15 @@ new function(window) {
|
||||||
var node, isNew = cached.nodes.length === 0
|
var node, isNew = cached.nodes.length === 0
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
node = window.document.createElement(data.tag)
|
node = window.document.createElement(data.tag)
|
||||||
cached = {tag: data.tag, attrs: setAttributes(node, data.attrs, {}), children: build(node, data.children, cached.children), nodes: [node]}
|
cached = {tag: data.tag, attrs: setAttributes(node, data.attrs, {}), children: build(node, data.children, cached.children, true), nodes: [node]}
|
||||||
parent.appendChild(node)
|
parent.appendChild(node)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
node = cached.nodes[0]
|
node = cached.nodes[0]
|
||||||
setAttributes(node, data.attrs, cached.attrs)
|
setAttributes(node, data.attrs, cached.attrs)
|
||||||
cached.children = build(node, data.children, cached.children)
|
cached.children = build(node, data.children, cached.children, false)
|
||||||
cached.nodes.intact = true
|
cached.nodes.intact = true
|
||||||
if (node.parentNode !== parent) parent.appendChild(node)
|
if (shouldReattach === true) parent.appendChild(node)
|
||||||
}
|
}
|
||||||
if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew)
|
if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew)
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +180,7 @@ new function(window) {
|
||||||
var index = nodeCache.indexOf(root)
|
var index = nodeCache.indexOf(root)
|
||||||
var id = index < 0 ? nodeCache.push(root) - 1 : index
|
var id = index < 0 ? nodeCache.push(root) - 1 : index
|
||||||
var node = root == window.document || root == window.document.documentElement ? documentNode : root
|
var node = root == window.document || root == window.document.documentElement ? documentNode : root
|
||||||
cellCache[id] = build(node, cell, cellCache[id])
|
cellCache[id] = build(node, cell, cellCache[id], false)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.trust = function(value) {
|
m.trust = function(value) {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ new function(window) {
|
||||||
}
|
}
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
function build(parent, data, cached) {
|
function build(parent, data, cached, shouldReattach) {
|
||||||
if (data === null || data === undefined) {
|
if (data === null || data === undefined) {
|
||||||
if (cached) clear(cached.nodes)
|
if (cached) clear(cached.nodes)
|
||||||
return
|
return
|
||||||
|
|
@ -49,7 +49,7 @@ new function(window) {
|
||||||
if (dataType == "[object Array]") {
|
if (dataType == "[object Array]") {
|
||||||
var nodes = [], intact = cached.length === data.length
|
var nodes = [], intact = cached.length === data.length
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (var i = 0; i < data.length; i++) {
|
||||||
var item = build(parent, data[i], cached[i])
|
var item = build(parent, data[i], cached[i], shouldReattach)
|
||||||
if (item === undefined) continue
|
if (item === undefined) continue
|
||||||
if (!item.nodes.intact) intact = false
|
if (!item.nodes.intact) intact = false
|
||||||
cached[i] = item
|
cached[i] = item
|
||||||
|
|
@ -69,15 +69,15 @@ new function(window) {
|
||||||
var node, isNew = cached.nodes.length === 0
|
var node, isNew = cached.nodes.length === 0
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
node = window.document.createElement(data.tag)
|
node = window.document.createElement(data.tag)
|
||||||
cached = {tag: data.tag, attrs: setAttributes(node, data.attrs, {}), children: build(node, data.children, cached.children), nodes: [node]}
|
cached = {tag: data.tag, attrs: setAttributes(node, data.attrs, {}), children: build(node, data.children, cached.children, true), nodes: [node]}
|
||||||
parent.appendChild(node)
|
parent.appendChild(node)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
node = cached.nodes[0]
|
node = cached.nodes[0]
|
||||||
setAttributes(node, data.attrs, cached.attrs)
|
setAttributes(node, data.attrs, cached.attrs)
|
||||||
cached.children = build(node, data.children, cached.children)
|
cached.children = build(node, data.children, cached.children, false)
|
||||||
cached.nodes.intact = true
|
cached.nodes.intact = true
|
||||||
if (node.parentNode !== parent) parent.appendChild(node)
|
if (shouldReattach === true) parent.appendChild(node)
|
||||||
}
|
}
|
||||||
if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew)
|
if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew)
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +180,7 @@ new function(window) {
|
||||||
var index = nodeCache.indexOf(root)
|
var index = nodeCache.indexOf(root)
|
||||||
var id = index < 0 ? nodeCache.push(root) - 1 : index
|
var id = index < 0 ? nodeCache.push(root) - 1 : index
|
||||||
var node = root == window.document || root == window.document.documentElement ? documentNode : root
|
var node = root == window.document || root == window.document.documentElement ? documentNode : root
|
||||||
cellCache[id] = build(node, cell, cellCache[id])
|
cellCache[id] = build(node, cell, cellCache[id], false)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.trust = function(value) {
|
m.trust = function(value) {
|
||||||
|
|
|
||||||
2
archive/v0.1.4/mithril.min.js
vendored
2
archive/v0.1.4/mithril.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
12
mithril.js
12
mithril.js
|
|
@ -32,7 +32,7 @@ new function(window) {
|
||||||
}
|
}
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
function build(parent, data, cached) {
|
function build(parent, data, cached, shouldReattach) {
|
||||||
if (data === null || data === undefined) {
|
if (data === null || data === undefined) {
|
||||||
if (cached) clear(cached.nodes)
|
if (cached) clear(cached.nodes)
|
||||||
return
|
return
|
||||||
|
|
@ -49,7 +49,7 @@ new function(window) {
|
||||||
if (dataType == "[object Array]") {
|
if (dataType == "[object Array]") {
|
||||||
var nodes = [], intact = cached.length === data.length
|
var nodes = [], intact = cached.length === data.length
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (var i = 0; i < data.length; i++) {
|
||||||
var item = build(parent, data[i], cached[i])
|
var item = build(parent, data[i], cached[i], shouldReattach)
|
||||||
if (item === undefined) continue
|
if (item === undefined) continue
|
||||||
if (!item.nodes.intact) intact = false
|
if (!item.nodes.intact) intact = false
|
||||||
cached[i] = item
|
cached[i] = item
|
||||||
|
|
@ -69,15 +69,15 @@ new function(window) {
|
||||||
var node, isNew = cached.nodes.length === 0
|
var node, isNew = cached.nodes.length === 0
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
node = window.document.createElement(data.tag)
|
node = window.document.createElement(data.tag)
|
||||||
cached = {tag: data.tag, attrs: setAttributes(node, data.attrs, {}), children: build(node, data.children, cached.children), nodes: [node]}
|
cached = {tag: data.tag, attrs: setAttributes(node, data.attrs, {}), children: build(node, data.children, cached.children, true), nodes: [node]}
|
||||||
parent.appendChild(node)
|
parent.appendChild(node)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
node = cached.nodes[0]
|
node = cached.nodes[0]
|
||||||
setAttributes(node, data.attrs, cached.attrs)
|
setAttributes(node, data.attrs, cached.attrs)
|
||||||
cached.children = build(node, data.children, cached.children)
|
cached.children = build(node, data.children, cached.children, false)
|
||||||
cached.nodes.intact = true
|
cached.nodes.intact = true
|
||||||
if (node.parentNode !== parent) parent.appendChild(node)
|
if (shouldReattach === true) parent.appendChild(node)
|
||||||
}
|
}
|
||||||
if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew)
|
if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew)
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +180,7 @@ new function(window) {
|
||||||
var index = nodeCache.indexOf(root)
|
var index = nodeCache.indexOf(root)
|
||||||
var id = index < 0 ? nodeCache.push(root) - 1 : index
|
var id = index < 0 ? nodeCache.push(root) - 1 : index
|
||||||
var node = root == window.document || root == window.document.documentElement ? documentNode : root
|
var node = root == window.document || root == window.document.documentElement ? documentNode : root
|
||||||
cellCache[id] = build(node, cell, cellCache[id])
|
cellCache[id] = build(node, cell, cellCache[id], false)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.trust = function(value) {
|
m.trust = function(value) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue