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
Make replaceNode atomic
joel.drapper.me
4 months ago
8e091b1b
087548b5
+7
-2
1 changed file
expand all
collapse all
unified
split
src
morphlex.ts
+7
-2
src/morphlex.ts
···
670
670
#replaceNode(node: ChildNode, newNode: ChildNode): void {
671
671
const parent = node.parentNode || document
672
672
const insertionPoint = node
673
673
-
if (this.#options.beforeNodeAdded?.(parent, newNode, insertionPoint) ?? true) {
673
673
+
// Check if both removal and addition are allowed before starting the replacement
674
674
+
if (
675
675
+
(this.#options.beforeNodeRemoved?.(node) ?? true) &&
676
676
+
(this.#options.beforeNodeAdded?.(parent, newNode, insertionPoint) ?? true)
677
677
+
) {
674
678
moveBefore(parent, newNode, insertionPoint)
675
679
this.#options.afterNodeAdded?.(newNode)
676
676
-
this.#removeNode(node)
680
680
+
node.remove()
681
681
+
this.#options.afterNodeRemoved?.(node)
677
682
}
678
683
}
679
684