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