nl_tokens: @private @description Utility that will nodes childern to match another nodes children .
pl_tokens: function setChildNodes ( oldParent , newParent ) { var checkOld , oldKey , checkNew , newKey , foundNode , keyedNodes var oldNode = oldParent . firstChild var newNode = newParent . firstChild var <mask> = 0 // Extract keyed nodes from previous children and keep track of total count. while ( oldNode ) { extra ++ checkOld = oldNode oldKey = getKey ( checkOld ) oldNode = oldNode . nextSibling if ( oldKey ) { if ( ! keyedNodes ) keyedNodes = { } keyedNodes [ oldKey ] = checkOld } } // Loop over new nodes and perform updates. oldNode = oldParent . firstChild while ( newNode ) { extra -- checkNew = newNode newNode = newNode . nextSibling if ( keyedNodes && ( newKey = getKey ( checkNew ) ) && ( foundNode = keyedNodes [ newKey ] ) ) { delete keyedNodes [ newKey ] // If we have a key and it existed before we move the previous node to the new position if needed and diff it. if ( foundNode !== oldNode ) { oldParent . insertBefore ( foundNode , oldNode ) } else { oldNode = oldNode . nextSibling } setNode ( foundNode , checkNew ) } else if ( oldNode ) { checkOld = oldNode oldNode = oldNode . nextSibling if ( getKey ( checkOld ) ) { // If the old child had a key we skip over it until the end. oldParent . insertBefore ( checkNew , checkOld ) mount ( checkNew ) } else { // Otherwise we diff the two non-keyed nodes. setNode ( checkOld , checkNew ) } } else { // Finally if there was no old node we add the new node. oldParent . appendChild ( checkNew ) mount ( checkNew ) } } // Remove old keyed nodes. for ( oldKey in keyedNodes ) { extra -- oldParent . removeChild ( dismount ( keyedNodes [ oldKey ] ) ) } // If we have any remaining unkeyed nodes remove them from the end. while ( -- extra >= 0 ) { oldParent . removeChild ( dismount ( oldParent . lastChild ) ) } }