(child)
| 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 |
no test coverage detected