Precise DOM morphing
morphing typescript dom
0
fork

Configure Feed

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

Change order of arguments

+18 -18
+14 -14
dist/morphlex.js
··· 41 41 const child = childNodes.at(i); 42 42 const guideChild = guideChildNodes.at(i); 43 43 if (child && guideChild) 44 - morphChildNode(child, guideChild, idMap, elem); 44 + morphChildNode(child, guideChild, elem, idMap); 45 45 else if (guideChild) 46 46 elem.appendChild(guideChild.cloneNode(true)); 47 47 } 48 48 while (elem.childNodes.length > guide.childNodes.length) 49 49 elem.lastChild?.remove(); 50 50 } 51 - function morphChildNode(child, guide, idMap, parent) { 51 + function morphChildNode(child, guide, parent, idMap) { 52 52 if (isElement(child) && isElement(guide)) 53 - morphChildElement(child, guide, idMap, parent); 53 + morphChildElement(child, guide, parent, idMap); 54 54 else 55 55 morphNodes(child, guide, idMap); 56 56 } 57 - function morphChildElement(child, guide, idMap, parent) { 57 + function morphChildElement(child, guide, parent, idMap) { 58 58 const guideIdSet = idMap.get(guide); 59 59 const guideSetArray = guideIdSet ? [...guideIdSet] : []; 60 - let current = child; 60 + let currentNode = child; 61 61 let nextMatchByTagName = null; 62 - while (current) { 63 - if (isElement(current)) { 64 - if (current.id !== "" && current.id === guide.id) { 65 - return morphNodes(current, guide, idMap, child, parent); 62 + while (currentNode) { 63 + if (isElement(currentNode)) { 64 + if (currentNode.id !== "" && currentNode.id === guide.id) { 65 + return morphNodes(currentNode, guide, idMap, child, parent); 66 66 } 67 67 else { 68 - const currentIdSet = idMap.get(current); 68 + const currentIdSet = idMap.get(currentNode); 69 69 if (currentIdSet && guideSetArray.some((it) => currentIdSet.has(it))) { 70 - return morphNodes(current, guide, idMap, child, parent); 70 + return morphNodes(currentNode, guide, idMap, child, parent); 71 71 } 72 - else if (!nextMatchByTagName && current.tagName === guide.tagName) { 73 - nextMatchByTagName = current; 72 + else if (!nextMatchByTagName && currentNode.tagName === guide.tagName) { 73 + nextMatchByTagName = currentNode; 74 74 } 75 75 } 76 76 } 77 - current = current.nextSibling; 77 + currentNode = currentNode.nextSibling; 78 78 } 79 79 if (nextMatchByTagName) 80 80 morphNodes(nextMatchByTagName, guide, idMap, child, parent);
+4 -4
src/morphlex.ts
··· 40 40 const child = childNodes.at(i); 41 41 const guideChild = guideChildNodes.at(i); 42 42 43 - if (child && guideChild) morphChildNode(child, guideChild, idMap, elem); 43 + if (child && guideChild) morphChildNode(child, guideChild, elem, idMap); 44 44 else if (guideChild) elem.appendChild(guideChild.cloneNode(true)); 45 45 } 46 46 ··· 48 48 while (elem.childNodes.length > guide.childNodes.length) elem.lastChild?.remove(); 49 49 } 50 50 51 - function morphChildNode(child: ChildNode, guide: ChildNode, idMap: IdMap, parent: Element): void { 52 - if (isElement(child) && isElement(guide)) morphChildElement(child, guide, idMap, parent); 51 + function morphChildNode(child: ChildNode, guide: ChildNode, parent: Element, idMap: IdMap): void { 52 + if (isElement(child) && isElement(guide)) morphChildElement(child, guide, parent, idMap); 53 53 else morphNodes(child, guide, idMap); 54 54 } 55 55 56 - function morphChildElement(child: Element, guide: Element, idMap: IdMap, parent: Element): void { 56 + function morphChildElement(child: Element, guide: Element, parent: Element, idMap: IdMap): void { 57 57 const guideIdSet = idMap.get(guide); 58 58 59 59 // Generate the array in advance of the loop