diff --git a/src/renderers/dom/client/utils/DOMChildrenOperations.js b/src/renderers/dom/client/utils/DOMChildrenOperations.js index 00143a9c3f38..c5c796325d08 100644 --- a/src/renderers/dom/client/utils/DOMChildrenOperations.js +++ b/src/renderers/dom/client/utils/DOMChildrenOperations.js @@ -18,7 +18,10 @@ var ReactPerf = require('ReactPerf'); var setInnerHTML = require('setInnerHTML'); var setTextContent = require('setTextContent'); -var invariant = require('invariant'); + +function getNodeAfter(parentNode, node) { + return node ? node.nextSibling : parentNode.firstChild; +} /** * Inserts `childNode` as a child of `parentNode` at the `index`. @@ -28,27 +31,14 @@ var invariant = require('invariant'); * @param {number} index Index at which to insert the child. * @internal */ -function insertChildAt(parentNode, childNode, index) { - // We can rely exclusively on `insertBefore(node, null)` instead of also using +function insertChildAt(parentNode, childNode, referenceNode) { + // We rely exclusively on `insertBefore(node, null)` instead of also using // `appendChild(node)`. (Using `undefined` is not allowed by all browsers so // we are careful to use `null`.) - - // In Safari, .childNodes[index] can return a DOM node with id={index} so we - // use .item() instead which is immune to this bug. (See #3560.) In contrast - // to the spec, IE8 throws an error if index is larger than the list size. - var referenceNode = - index < parentNode.childNodes.length ? - parentNode.childNodes.item(index) : null; - parentNode.insertBefore(childNode, referenceNode); } -function insertLazyTreeChildAt(parentNode, childTree, index) { - // See above. - var referenceNode = - index < parentNode.childNodes.length ? - parentNode.childNodes.item(index) : null; - +function insertLazyTreeChildAt(parentNode, childTree, referenceNode) { DOMLazyTree.insertTreeBefore(parentNode, childTree, referenceNode); } @@ -69,81 +59,21 @@ var DOMChildrenOperations = { * @internal */ processUpdates: function(parentNode, updates) { - var update; - // Mapping from parent IDs to initial child orderings. - var initialChildren = null; - // List of children that will be moved or removed. - var updatedChildren = null; - - var markupList = null; - - for (var i = 0; i < updates.length; i++) { - update = updates[i]; - if (update.type === ReactMultiChildUpdateTypes.MOVE_EXISTING || - update.type === ReactMultiChildUpdateTypes.REMOVE_NODE) { - var updatedIndex = update.fromIndex; - var updatedChild = parentNode.childNodes[updatedIndex]; - - invariant( - updatedChild, - 'processUpdates(): Unable to find child %s of element %s. This ' + - 'probably means the DOM was unexpectedly mutated (e.g., by the ' + - 'browser), usually due to forgetting a
when using tables, ' + - 'nesting tags like