Skip to content

Commit

Permalink
Rename elem to element
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Feb 25, 2024
1 parent 33f88fb commit 001e7e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions dist/morphlex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/morphlex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@ function morphAttributes(elm: Element, ref: Element): void {
}

// Iterates over the child nodes of the reference element, morphing the main element’s child nodes to match.
function morphChildNodes(elem: Element, ref: Element, idMap: IdMap): void {
const childNodes = [...elem.childNodes];
function morphChildNodes(element: Element, ref: Element, idMap: IdMap): void {
const childNodes = [...element.childNodes];
const refChildNodes = [...ref.childNodes];

for (let i = 0; i < refChildNodes.length; i++) {
const child = childNodes.at(i);
const refChild = refChildNodes.at(i);

if (child && refChild) morphChildNode(child, refChild, elem, idMap);
else if (refChild) elem.appendChild(refChild.cloneNode(true));
if (child && refChild) morphChildNode(child, refChild, element, idMap);
else if (refChild) element.appendChild(refChild.cloneNode(true));
else if (child) child.remove();
}

// Remove any excess child nodes from the main element. This is separate because
// the loop above might modify the length of the main element’s child nodes.
while (elem.childNodes.length > ref.childNodes.length) elem.lastChild?.remove();
while (element.childNodes.length > ref.childNodes.length) element.lastChild?.remove();
}

function morphChildNode(child: ChildNode, ref: ChildNode, parent: Element, idMap: IdMap): void {
Expand Down

0 comments on commit 001e7e6

Please sign in to comment.