swapdom
Fast & tiny DOM swapper.
import swap from './swap-inflate.js'
swap(parentNode, oldNodes, newNodes, endNode)
swap-deflate.js
strategy is smaller (208b), but slower and doesn't support live collections.
swap-inflate.js
strategy is bigger (363b), but faster and supports live collections.
Provide custom mutators as:
swap.same = (a,b) => a?.isSameNode(b)
swap.replace = (a,b, parent) => a.replaceWith(b)
swap.insert = (a,b, parent) => a ? a.before(b) : parent.append(b)
swap.remove = (a, parent) => a.remove()
See benchmark.
ॐ