swapdom

Fast & tiny DOM swapper.

Usage no npm install needed!

<script type="module">
  import swapdom from 'https://cdn.skypack.dev/swapdom';
</script>

README

swapdom test npm version

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.