Precise DOM morphing
morphing typescript dom
0
fork

Configure Feed

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

Rename `nextMatchByTagName` for clarify

+9 -9
+5 -5
dist/morphlite.js
··· 54 54 function morphChildNode(child, guide, idMap, parent) { 55 55 if (isElement(child) && isElement(guide)) { 56 56 let current = child; 57 - let nextBestMatch = null; 57 + let nextMatchByTagName = null; 58 58 while (current) { 59 59 if (isElement(current)) { 60 60 if (current.id !== "" && current.id === guide.id) { ··· 67 67 if (a && b && [...a].some((it) => b.has(it))) { 68 68 return morphNodes(current, guide, idMap, child, parent); 69 69 } 70 - else if (!nextBestMatch && current.tagName === guide.tagName) { 71 - nextBestMatch = current; 70 + else if (!nextMatchByTagName && current.tagName === guide.tagName) { 71 + nextMatchByTagName = current; 72 72 } 73 73 } 74 74 } 75 75 current = current.nextSibling; 76 76 } 77 - if (nextBestMatch) 78 - morphNodes(nextBestMatch, guide, idMap, child, parent); 77 + if (nextMatchByTagName) 78 + morphNodes(nextMatchByTagName, guide, idMap, child, parent); 79 79 else 80 80 child.replaceWith(guide.cloneNode(true)); 81 81 }
+4 -4
src/morphlite.ts
··· 49 49 function morphChildNode(child: ChildNode, guide: ChildNode, idMap: IdMap, parent: Element): void { 50 50 if (isElement(child) && isElement(guide)) { 51 51 let current: ChildNode | null = child; 52 - let nextBestMatch: ChildNode | null = null; 52 + let nextMatchByTagName: ChildNode | null = null; 53 53 54 54 while (current) { 55 55 if (isElement(current)) { ··· 62 62 63 63 if (a && b && [...a].some((it) => b.has(it))) { 64 64 return morphNodes(current, guide, idMap, child, parent); 65 - } else if (!nextBestMatch && current.tagName === guide.tagName) { 66 - nextBestMatch = current; 65 + } else if (!nextMatchByTagName && current.tagName === guide.tagName) { 66 + nextMatchByTagName = current; 67 67 } 68 68 } 69 69 } ··· 71 71 current = current.nextSibling; 72 72 } 73 73 74 - if (nextBestMatch) morphNodes(nextBestMatch, guide, idMap, child, parent); 74 + if (nextMatchByTagName) morphNodes(nextMatchByTagName, guide, idMap, child, parent); 75 75 else child.replaceWith(guide.cloneNode(true)); 76 76 } else morphNodes(child, guide, idMap); 77 77 }