An essential diffing algorithm for µhtml
npm install udomdiff 
Social Media Photo by Christopher Rusev on Unsplash
An essential diffing algorithm for µhtml.
``js`
futureNodes = udomdiff(
parentNode, // where changes happen
[...currentNodes], // Array of current items/nodes
[...futureNodes], // Array of future items/nodes (returned)
get(node, toDoWhat), // a callback to retrieve the node
before // the anchored node to insertBefore
);
You can find all info from domdiff, as it's exactly the same concept:
* get(node, 1) to retrieve the node that's being appendedget(node, 0)
* to get the node to use for an insertBefore operationget(node, -0)
* to get the node to use for an insertAfter operationget(node, -1)
* to retrieve the node that's being removed
If you don't care about any of those second arguments values, const get = o => o; is a valid get too.
* via CDN, as global variable: https://unpkg.com/udomdiffimport udomdiff from 'https://unpkg.com/udomdiff/esm/index.js'
* via ESM, as external module: const udomdiff = require('udomdiff');
* via CJS: ( or require('udomdiff/cjs') )import udomdiff from 'udomdiff';
* via bundlers/transpilers: ( or from 'udomdiff/esm'` )