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

Function postorder

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

Source from the content-addressed store, hash-verified

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

Callers 1

traversalFunction · 0.85

Calls 2

updateTreeFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected