Precise DOM morphing
morphing typescript dom
0
fork

Configure Feed

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

Rename `elem` to `element`

+10 -10
+5 -5
dist/morphlex.js
··· 62 62 } 63 63 } 64 64 // Iterates over the child nodes of the reference element, morphing the main element’s child nodes to match. 65 - function morphChildNodes(elem, ref, idMap) { 66 - const childNodes = [...elem.childNodes]; 65 + function morphChildNodes(element, ref, idMap) { 66 + const childNodes = [...element.childNodes]; 67 67 const refChildNodes = [...ref.childNodes]; 68 68 for (let i = 0; i < refChildNodes.length; i++) { 69 69 const child = childNodes.at(i); 70 70 const refChild = refChildNodes.at(i); 71 - if (child && refChild) morphChildNode(child, refChild, elem, idMap); 72 - else if (refChild) elem.appendChild(refChild.cloneNode(true)); 71 + if (child && refChild) morphChildNode(child, refChild, element, idMap); 72 + else if (refChild) element.appendChild(refChild.cloneNode(true)); 73 73 else if (child) child.remove(); 74 74 } 75 75 // Remove any excess child nodes from the main element. This is separate because 76 76 // the loop above might modify the length of the main element’s child nodes. 77 - while (elem.childNodes.length > ref.childNodes.length) elem.lastChild?.remove(); 77 + while (element.childNodes.length > ref.childNodes.length) element.lastChild?.remove(); 78 78 } 79 79 function morphChildNode(child, ref, parent, idMap) { 80 80 if (isElement(child) && isElement(ref)) morphChildElement(child, ref, parent, idMap);
+5 -5
src/morphlex.ts
··· 79 79 } 80 80 81 81 // Iterates over the child nodes of the reference element, morphing the main element’s child nodes to match. 82 - function morphChildNodes(elem: Element, ref: Element, idMap: IdMap): void { 83 - const childNodes = [...elem.childNodes]; 82 + function morphChildNodes(element: Element, ref: Element, idMap: IdMap): void { 83 + const childNodes = [...element.childNodes]; 84 84 const refChildNodes = [...ref.childNodes]; 85 85 86 86 for (let i = 0; i < refChildNodes.length; i++) { 87 87 const child = childNodes.at(i); 88 88 const refChild = refChildNodes.at(i); 89 89 90 - if (child && refChild) morphChildNode(child, refChild, elem, idMap); 91 - else if (refChild) elem.appendChild(refChild.cloneNode(true)); 90 + if (child && refChild) morphChildNode(child, refChild, element, idMap); 91 + else if (refChild) element.appendChild(refChild.cloneNode(true)); 92 92 else if (child) child.remove(); 93 93 } 94 94 95 95 // Remove any excess child nodes from the main element. This is separate because 96 96 // the loop above might modify the length of the main element’s child nodes. 97 - while (elem.childNodes.length > ref.childNodes.length) elem.lastChild?.remove(); 97 + while (element.childNodes.length > ref.childNodes.length) element.lastChild?.remove(); 98 98 } 99 99 100 100 function morphChildNode(child: ChildNode, ref: ChildNode, parent: Element, idMap: IdMap): void {