Skip to content

Commit

Permalink
Improve naming
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Mar 8, 2024
1 parent c58c97b commit 8425144
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 6 additions & 5 deletions dist/morphlex.js

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

11 changes: 6 additions & 5 deletions src/morphlex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,18 @@ class Morph {
if (isElement(node) && isElement(ref) && node.localName === ref.localName) {
if (node.hasAttributes() || ref.hasAttributes()) this.#morphAttributes(node, ref);
if (isHead(node) && isHead(ref)) {
const refChildNodes: Map<string, ReadonlyNode<Element>> = new Map();
for (const child of ref.children) refChildNodes.set(child.outerHTML, child);
const refChildNodesMap: Map<string, ReadonlyNode<Element>> = new Map();
for (const child of ref.children) refChildNodesMap.set(child.outerHTML, child);
for (const child of node.children) {
const key = child.outerHTML;
const refChild = refChildNodes.get(key);
refChild ? refChildNodes.delete(key) : this.#removeNode(child);
const refChild = refChildNodesMap.get(key);
refChild ? refChildNodesMap.delete(key) : this.#removeNode(child);
}
for (const refChild of refChildNodes.values()) this.#appendChild(node, refChild.cloneNode(true));
for (const refChild of refChildNodesMap.values()) this.#appendChild(node, refChild.cloneNode(true));
} else if (node.hasChildNodes() || ref.hasChildNodes()) this.#morphChildNodes(node, ref);
} else {
if (node.nodeType === ref.nodeType && node.nodeValue !== null && ref.nodeValue !== null) {
// Handle text nodes, comments, and CDATA sections.
this.#updateProperty(node, "nodeValue", ref.nodeValue);
} else this.#replaceNode(node, ref.cloneNode(true));
}
Expand Down

0 comments on commit 8425144

Please sign in to comment.