MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / commitPlacement

Function commitPlacement

code/one-direction-data-flow/public/app.js:11530–11598  ·  view source on GitHub ↗
(finishedWork)

Source from the content-addressed store, hash-verified

11528 }
11529
11530 function commitPlacement(finishedWork) {
11531 // Recursively insert all host nodes into the parent.
11532 var parentFiber = getHostParentFiber(finishedWork);
11533 var parent = void 0;
11534 var isContainer = void 0;
11535 switch (parentFiber.tag) {
11536 case HostComponent:
11537 parent = parentFiber.stateNode;
11538 isContainer = false;
11539 break;
11540 case HostRoot:
11541 parent = parentFiber.stateNode.containerInfo;
11542 isContainer = true;
11543 break;
11544 case HostPortal:
11545 parent = parentFiber.stateNode.containerInfo;
11546 isContainer = true;
11547 break;
11548 default:
11549 invariant(false, 'Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue.');
11550 }
11551 if (parentFiber.effectTag & ContentReset) {
11552 // Reset the text content of the parent before doing any insertions
11553 resetTextContent(parent);
11554 // Clear ContentReset from the effect tag
11555 parentFiber.effectTag &= ~ContentReset;
11556 }
11557
11558 var before = getHostSibling(finishedWork);
11559 // We only have the top Fiber that was inserted but we need recurse down its
11560 // children to find all the terminal nodes.
11561 var node = finishedWork;
11562 while (true) {
11563 if (node.tag === HostComponent || node.tag === HostText) {
11564 if (before) {
11565 if (isContainer) {
11566 insertInContainerBefore(parent, node.stateNode, before);
11567 } else {
11568 insertBefore(parent, node.stateNode, before);
11569 }
11570 } else {
11571 if (isContainer) {
11572 appendChildToContainer(parent, node.stateNode);
11573 } else {
11574 appendChild(parent, node.stateNode);
11575 }
11576 }
11577 } else if (node.tag === HostPortal) {
11578 // If the insertion itself is a portal, then we don't want to traverse
11579 // down its children. Instead, we'll get insertions from each child in
11580 // the portal directly.
11581 } else if (node.child !== null) {
11582 node.child['return'] = node;
11583 node = node.child;
11584 continue;
11585 }
11586 if (node === finishedWork) {
11587 return;

Callers 1

commitAllHostEffectsFunction · 0.70

Calls 3

getHostParentFiberFunction · 0.70
invariantFunction · 0.70
getHostSiblingFunction · 0.70

Tested by

no test coverage detected