mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
Merge pull request #879 from syranide/inlinechild
Remove unnecessary tests from insertChildAt and inline it instead
This commit is contained in:
commit
a0dc45e652
|
|
@ -42,20 +42,14 @@ var textContentAccessor = getTextContentAccessor();
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
function insertChildAt(parentNode, childNode, index) {
|
function insertChildAt(parentNode, childNode, index) {
|
||||||
var childNodes = parentNode.childNodes;
|
// By exploiting arrays returning `undefined` for an undefined index, we can
|
||||||
if (childNodes[index] === childNode) {
|
// rely exclusively on `insertBefore(node, null)` instead of also using
|
||||||
return;
|
// `appendChild(node)`. However, using `undefined` is not allowed by all
|
||||||
}
|
// browsers so we must replace it with `null`.
|
||||||
// If `childNode` is already a child of `parentNode`, remove it so that
|
parentNode.insertBefore(
|
||||||
// computing `childNodes[index]` takes into account the removal.
|
childNode,
|
||||||
if (childNode.parentNode === parentNode) {
|
parentNode.childNodes[index] || null
|
||||||
parentNode.removeChild(childNode);
|
);
|
||||||
}
|
|
||||||
if (index >= childNodes.length) {
|
|
||||||
parentNode.appendChild(childNode);
|
|
||||||
} else {
|
|
||||||
parentNode.insertBefore(childNode, childNodes[index]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateTextContent;
|
var updateTextContent;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user