From ecb14178120021d96da14c08836b805489c06672 Mon Sep 17 00:00:00 2001 From: Paul Grenier Date: Sun, 4 Sep 2016 14:41:15 -0400 Subject: [PATCH 1/2] provides simple mechanism to support using cached nodes and nodes that get augmented outside of the morphdom render cycle --- src/index.js | 8 ++++++++ test/browser/test.js | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/index.js b/src/index.js index 42a4411..5d0237f 100644 --- a/src/index.js +++ b/src/index.js @@ -372,6 +372,10 @@ function morphdom(fromNode, toNode, options) { delete fromNodesLookup[toElKey]; } + if (toNode.isSameNode(fromNode)) { + return; + } + if (!childrenOnly) { if (onBeforeElUpdated(fromEl, toEl) === false) { return; @@ -399,6 +403,10 @@ function morphdom(fromNode, toNode, options) { curToNodeKey = getNodeKey(curToNodeChild); while (curFromNodeChild) { + if (curToNodeChild.isSameNode(curFromNodeChild)) { + return; + } + curFromNodeKey = getNodeKey(curFromNodeChild); fromNextSibling = curFromNodeChild.nextSibling; diff --git a/test/browser/test.js b/test/browser/test.js index 070926a..18f7d25 100644 --- a/test/browser/test.js +++ b/test/browser/test.js @@ -726,6 +726,23 @@ function addTests() { expect(el1.querySelector('#skipMeChild') != null).to.equal(true); }); + it('should use isSameNode to allow reference proxies', function() { + var el1 = document.createElement('div'); + el1.innerHTML = 'stay gold'; + var el2 = document.createElement('div'); + el2.innerHTML = 'ponyboy'; + el2.isSameNode = function (el) {return el.isSameNode(el1)}; + morphdom(el1, el2); + expect(el1.innerHTML).to.equal('stay gold'); + + var containEl1 = document.createElement('div'); + containEl1.appendChild(el1); + var containEl2 = document.createElement('div'); + containEl2.appendChild(el2); + morphdom(containEl1, containEl2); + expect(el1.innerHTML).to.equal('stay gold'); + }); + // xit('should reuse DOM element with matching ID and class name (2)', function() { // // NOTE: This test is currently failing. We need to improve the special case code // // for handling incompatible root nodes. From df2a69f89d4872918ffcc5b5416e6efad7ad5c8b Mon Sep 17 00:00:00 2001 From: Paul Grenier Date: Sun, 4 Sep 2016 16:13:53 -0400 Subject: [PATCH 2/2] update to prevent failures in IE7, 8 --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 5d0237f..f6b8458 100644 --- a/src/index.js +++ b/src/index.js @@ -372,7 +372,7 @@ function morphdom(fromNode, toNode, options) { delete fromNodesLookup[toElKey]; } - if (toNode.isSameNode(fromNode)) { + if (toNode.isSameNode && toNode.isSameNode(fromNode)) { return; } @@ -403,7 +403,7 @@ function morphdom(fromNode, toNode, options) { curToNodeKey = getNodeKey(curToNodeChild); while (curFromNodeChild) { - if (curToNodeChild.isSameNode(curFromNodeChild)) { + if (curToNodeChild.isSameNode && curToNodeChild.isSameNode(curFromNodeChild)) { return; }