/** Apply child and attribute changes between a VNode and a DOM Node to the DOM. * @param {Element} dom Element whose children should be compared & mutated * @param {Array} vchildren Array of VNodes to compare to `dom.childNodes` * @param {Object} context Implicitly descendant context object (from most recent `getChildContext()`) * @param {Boolean} mountAll * @param {Boolean} absorb If `true`, consumes externally created elements similar to hydration */ function innerDiffNode(dom, vchildren, context, mountAll, absorb) { let originalChildren = dom.childNodes, children = [], keyed = {}, keyedLen = 0, min = 0, len = originalChildren.length, childrenLen = 0, vlen = vchildren && vchildren.length, j, c, vchild, child; if (len) { for (let i=0; i=len) { dom.appendChild(child); } else if (child!==originalChildren[i]) { if (child===originalChildren[i+1]) { removeNode(originalChildren[i]); } dom.insertBefore(child, originalChildren[i] || null); } } } } if (keyedLen) { for (let i in keyed) if (keyed[i]) recollectNodeTree(keyed[i]); } // remove orphaned children while (min<=childrenLen) { child = children[childrenLen--]; if (child) recollectNodeTree(child); } }