From f4b267ff39686e2d6f0dc4a86a533e4416137c9c Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Sat, 30 Jul 2016 15:46:14 -0400 Subject: [PATCH] don't duplicate html on updates --- mithril.js | 6 +++--- render/render.js | 4 ++-- render/tests/test-updateHTML.js | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mithril.js b/mithril.js index d5fd9668..e9c04d15 100644 --- a/mithril.js +++ b/mithril.js @@ -456,7 +456,7 @@ var renderService = function($window) { toFragment(old) 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) { updateNodes(parent, old.children, vnode.children, hooks, nextSibling, ns) @@ -1042,7 +1042,7 @@ var throttle = function(callback) { var last = 0, pending = null var timeout = typeof requestAnimationFrame === "function" ? requestAnimationFrame : setTimeout return function(synchronous) { - var now = new Date().getTime() + var now = Date.now() if (synchronous === true || last === 0 || now - last >= time) { last = now callback() @@ -1051,7 +1051,7 @@ var throttle = function(callback) { pending = timeout(function() { pending = null callback() - last = new Date().getTime() + last = Date.now() }, time - (now - last)) } } diff --git a/render/render.js b/render/render.js index 29fc9b7d..a387e687 100644 --- a/render/render.js +++ b/render/render.js @@ -216,7 +216,7 @@ module.exports = function($window) { toFragment(old) 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) { 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 (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] else context.pool.push(vnode) } diff --git a/render/tests/test-updateHTML.js b/render/tests/test-updateHTML.js index 04b27558..c678e539 100644 --- a/render/tests/test-updateHTML.js +++ b/render/tests/test-updateHTML.js @@ -20,6 +20,7 @@ o.spec("updateHTML", function() { render(root, [updated]) o(updated.dom).equals(root.firstChild) + o(updated.domSize).equals(1) o(updated.dom.nodeValue).equals("b") }) o("adds html", function() {