/*! Emerj v1.0.0 | MIT LICENSE | https://github.com/bryhoyt/emerj */ var diff = { attrs(elem) { const attrs = {}; for (let i=0; i < elem.attributes.length; i++) { const attr = elem.attributes[i]; attrs[attr.name] = attr.value; } return attrs; }, nodesByKey(parent, makeKey) { const map = {}; for (let j=0; j < parent.childNodes.length; j++) { const key = makeKey(parent.childNodes[j]); if (key) map[key] = parent.childNodes[j]; } return map; }, merge(base, modified, opts) { /* Merge any differences between base and modified back into base. * * Operates only the children nodes, and does not change the root node or its * attributes. * * Conceptually similar to React's reconciliation algorithm: * https://facebook.github.io/react/docs/reconciliation.html * * I haven't thoroughly tested performance to compare to naive DOM updates (i.e. * just updating the entire DOM from a string using .innerHTML), but some quick * tests on a basic DOMs were twice as fast -- so at least it's not slower in * a simple scenario -- and it's definitely "fast enough" for responsive UI and * even smooth animation. * * The real advantage for me is not so much performance, but that state & identity * of existing elements is preserved -- text typed into an , an open *