Precise DOM morphing
morphing typescript dom
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update morphlite.js

+5 -5
+5 -5
dist/morphlite.js
··· 15 15 } 16 16 else if (isElement(node) && isElement(guide)) { 17 17 if (node.tagName === guide.tagName) { 18 - if (node.attributes.length > 0 || guide.attributes.length > 0) 18 + if (node.hasAttributes() || guide.hasAttributes()) 19 19 morphAttributes(node, guide); 20 - if (node.childNodes.length > 0 || guide.childNodes.length > 0) 20 + if (node.hasChildNodes() || guide.hasChildNodes()) 21 21 morphChildNodes(node, guide, idMap); 22 22 } 23 23 else ··· 63 63 else { 64 64 const setA = idMap.get(current); 65 65 const setB = idMap.get(guide); 66 - if (setA && setB && numberOfItemsInCommon(setA, setB) > 0) { 66 + if (setA && setB && hasItemInCommon(setA, setB)) { 67 67 return morphNodes(current, guide, idMap, child, parent); 68 68 } 69 69 else if (!nextBestMatch && current.tagName === guide.tagName) { ··· 94 94 } 95 95 } 96 96 } 97 - function numberOfItemsInCommon(a, b) { 98 - return [...a].filter((item) => b.has(item)).length; 97 + function hasItemInCommon(a, b) { 98 + return [...a].some((item) => b.has(item)); 99 99 } 100 100 function isElement(node) { 101 101 return node.nodeType === 1;