tangled
alpha
login
or
join now
yippee.fun
/
morphlex
0
fork
atom
Precise DOM morphing
morphing
typescript
dom
0
fork
atom
overview
issues
pulls
pipelines
Use `moveBefore`
joel.drapper.me
4 months ago
621ac45b
929c7535
+9
-1
1 changed file
expand all
collapse all
unified
split
src
morphlex.ts
+9
-1
src/morphlex.ts
···
73
73
else throw new Error("[Morphlex] The string was not a valid HTML node.")
74
74
}
75
75
76
76
+
// Feature detection for moveBefore support (cached for performance)
77
77
+
const supportsMoveBefore = typeof Element.prototype.moveBefore === "function"
78
78
+
76
79
class Morph {
77
80
readonly #idMap: IdMap
78
81
···
380
383
#insertBefore(parent: ParentNode, node: Node, insertionPoint: ChildNode): void {
381
384
if (node === insertionPoint) return
382
385
383
383
-
parent.insertBefore(node, insertionPoint)
386
386
+
// Use moveBefore when available (more efficient for moving existing nodes)
387
387
+
if (supportsMoveBefore) {
388
388
+
;(parent as any).moveBefore(node, insertionPoint)
389
389
+
} else {
390
390
+
parent.insertBefore(node, insertionPoint)
391
391
+
}
384
392
}
385
393
386
394
#appendChild(node: ParentNode, newNode: Node): void {