MCPcopy Create free account
hub / github.com/adobe/react-spectrum / postorder

Function postorder

packages/react-stately/src/data/useTreeData.ts:528–552  ·  view source on GitHub ↗
(child)

Source from the content-addressed store, hash-verified

526 }
527
528 function postorder(child) {
529 // remove items and update the tree from the leaves and work upwards toward the root, this way
530 // we don't copy child node references from parents inadvertently
531 if (keyArray.includes(child.key)) {
532 removedItems.push({...newMap.get(child.key)!, parentKey: toParent?.key ?? null});
533 let {items: nextItems, nodeMap: nextMap} = updateTree(
534 newItems,
535 child.key,
536 () => null,
537 newMap
538 );
539 newItems = nextItems;
540 newMap = nextMap;
541 }
542 // decrement the index if the child being removed is in the target parent and before the target index
543 // the root node is special, it is null, and will not have a key, however, a parentKey can still point to it
544 if (
545 (child.parentKey === toParent || child.parentKey === toParent?.key) &&
546 keyArray.includes(child.key) &&
547 (toParent?.children ? toParent.children.indexOf(child) : items.indexOf(child)) <
548 originalToIndex
549 ) {
550 toIndex--;
551 }
552 }
553
554 traversal({children: items}, {inorder, postorder});
555

Callers 1

traversalFunction · 0.85

Calls 2

updateTreeFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected