* Recursively walks the tree to find leaf nodes, update the resize handles, and compute additional properties for each node. * @param balanceTree Whether the tree should also be balanced as it is walked. This should be done if the tree state has just been updated. Defaults to true.
(balanceTree = true)
| 722 | * @param balanceTree Whether the tree should also be balanced as it is walked. This should be done if the tree state has just been updated. Defaults to true. |
| 723 | */ |
| 724 | updateTree(balanceTree = true) { |
| 725 | if (this.displayContainerRef.current) { |
| 726 | const newLeafs: LayoutNode[] = []; |
| 727 | const newAdditionalProps = {}; |
| 728 | |
| 729 | const pendingAction = this.getter(this.pendingTreeAction.currentValueAtom); |
| 730 | const resizeAction = |
| 731 | pendingAction?.type === LayoutTreeActionType.ResizeNode |
| 732 | ? (pendingAction as LayoutTreeResizeNodeAction) |
| 733 | : null; |
| 734 | const resizeHandleSizePx = this.getter(this.resizeHandleSizePx); |
| 735 | |
| 736 | const boundingRect = this.getBoundingRect(); |
| 737 | |
| 738 | const magnifiedNodeSize = this.getter(this.magnifiedNodeSizeAtom); |
| 739 | |
| 740 | const callback = (node: LayoutNode) => |
| 741 | this.updateTreeHelper( |
| 742 | node, |
| 743 | newAdditionalProps, |
| 744 | newLeafs, |
| 745 | resizeHandleSizePx, |
| 746 | magnifiedNodeSize, |
| 747 | boundingRect, |
| 748 | resizeAction |
| 749 | ); |
| 750 | if (balanceTree) this.treeState.rootNode = balanceNode(this.treeState.rootNode, callback); |
| 751 | else walkNodes(this.treeState.rootNode, callback); |
| 752 | |
| 753 | // Process ephemeral node, if present. |
| 754 | const ephemeralNode = this.getter(this.ephemeralNode); |
| 755 | if (ephemeralNode) { |
| 756 | this.updateEphemeralNodeProps( |
| 757 | ephemeralNode, |
| 758 | newAdditionalProps, |
| 759 | newLeafs, |
| 760 | magnifiedNodeSize, |
| 761 | boundingRect |
| 762 | ); |
| 763 | } |
| 764 | |
| 765 | this.treeState.leafOrder = getLeafOrder(newLeafs, newAdditionalProps); |
| 766 | this.validateFocusedNode(this.treeState.leafOrder); |
| 767 | this.validateMagnifiedNode(this.treeState.leafOrder, newAdditionalProps); |
| 768 | this.cleanupNodeModels(this.treeState.leafOrder); |
| 769 | this.setter( |
| 770 | this.leafs, |
| 771 | newLeafs.sort((a, b) => a.id.localeCompare(b.id)) |
| 772 | ); |
| 773 | this.setter(this.leafOrder, this.treeState.leafOrder); |
| 774 | this.setter(this.additionalProps, newAdditionalProps); |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * Per-node callback that is invoked recursively to find leaf nodes, update the resize handles, and compute additional properties associated with the given node. |
no test coverage detected