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
|
||||
*/
|
||||
function insertChildAt(parentNode, childNode, index) {
|
||||
var childNodes = parentNode.childNodes;
|
||||
if (childNodes[index] === childNode) {
|
||||
return;
|
||||
}
|
||||
// If `childNode` is already a child of `parentNode`, remove it so that
|
||||
// computing `childNodes[index]` takes into account the removal.
|
||||
if (childNode.parentNode === parentNode) {
|
||||
parentNode.removeChild(childNode);
|
||||
}
|
||||
if (index >= childNodes.length) {
|
||||
parentNode.appendChild(childNode);
|
||||
} else {
|
||||
parentNode.insertBefore(childNode, childNodes[index]);
|
||||
}
|
||||
// By exploiting arrays returning `undefined` for an undefined index, we can
|
||||
// rely exclusively on `insertBefore(node, null)` instead of also using
|
||||
// `appendChild(node)`. However, using `undefined` is not allowed by all
|
||||
// browsers so we must replace it with `null`.
|
||||
parentNode.insertBefore(
|
||||
childNode,
|
||||
parentNode.childNodes[index] || null
|
||||
);
|
||||
}
|
||||
|
||||
var updateTextContent;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user