don't duplicate html on updates

This commit is contained in:
Leo Horie 2016-07-30 15:46:14 -04:00
parent 9bd0cd73fc
commit f4b267ff39
3 changed files with 6 additions and 5 deletions

View file

@ -456,7 +456,7 @@ var renderService = function($window) {
toFragment(old) toFragment(old)
insertNode(parent, createHTML(vnode), nextSibling) insertNode(parent, createHTML(vnode), nextSibling)
} }
else vnode.dom = old.dom else vnode.dom = old.dom, vnode.domSize = old.domSize
} }
function updateFragment(parent, old, vnode, hooks, nextSibling, ns) { function updateFragment(parent, old, vnode, hooks, nextSibling, ns) {
updateNodes(parent, old.children, vnode.children, hooks, nextSibling, ns) updateNodes(parent, old.children, vnode.children, hooks, nextSibling, ns)
@ -1042,7 +1042,7 @@ var throttle = function(callback) {
var last = 0, pending = null var last = 0, pending = null
var timeout = typeof requestAnimationFrame === "function" ? requestAnimationFrame : setTimeout var timeout = typeof requestAnimationFrame === "function" ? requestAnimationFrame : setTimeout
return function(synchronous) { return function(synchronous) {
var now = new Date().getTime() var now = Date.now()
if (synchronous === true || last === 0 || now - last >= time) { if (synchronous === true || last === 0 || now - last >= time) {
last = now last = now
callback() callback()
@ -1051,7 +1051,7 @@ var throttle = function(callback) {
pending = timeout(function() { pending = timeout(function() {
pending = null pending = null
callback() callback()
last = new Date().getTime() last = Date.now()
}, time - (now - last)) }, time - (now - last))
} }
} }

View file

@ -216,7 +216,7 @@ module.exports = function($window) {
toFragment(old) toFragment(old)
insertNode(parent, createHTML(vnode), nextSibling) insertNode(parent, createHTML(vnode), nextSibling)
} }
else vnode.dom = old.dom else vnode.dom = old.dom, vnode.domSize = old.domSize
} }
function updateFragment(parent, old, vnode, hooks, nextSibling, ns) { function updateFragment(parent, old, vnode, hooks, nextSibling, ns) {
updateNodes(parent, old.children, vnode.children, hooks, nextSibling, ns) updateNodes(parent, old.children, vnode.children, hooks, nextSibling, ns)
@ -356,7 +356,7 @@ module.exports = function($window) {
} }
} }
if (vnode.dom.parentNode != null) parent.removeChild(vnode.dom) if (vnode.dom.parentNode != null) parent.removeChild(vnode.dom)
if (context != null && vnode.domSize == null && !hasIntegrationMethods(vnode.attrs) && typeof vnode.tag === "string") { //TODO test custom elements if (context != null && vnode.domSize == null && !hasIntegrationMethods(vnode.attrs) && typeof vnode.tag === "string" && vnode.tag !== "<") { //TODO test custom elements
if (!context.pool) context.pool = [vnode] if (!context.pool) context.pool = [vnode]
else context.pool.push(vnode) else context.pool.push(vnode)
} }

View file

@ -20,6 +20,7 @@ o.spec("updateHTML", function() {
render(root, [updated]) render(root, [updated])
o(updated.dom).equals(root.firstChild) o(updated.dom).equals(root.firstChild)
o(updated.domSize).equals(1)
o(updated.dom.nodeValue).equals("b") o(updated.dom.nodeValue).equals("b")
}) })
o("adds html", function() { o("adds html", function() {