MCPcopy
hub / github.com/wavetermdev/waveterm / updateTree

Method updateTree

frontend/layout/lib/layoutModel.ts:724–776  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 7

treeReducerMethod · 0.95
closeNodeMethod · 0.95
LayoutModelClass · 0.95
onResizeMoveMethod · 0.95

Calls 7

validateFocusedNodeMethod · 0.95
validateMagnifiedNodeMethod · 0.95
cleanupNodeModelsMethod · 0.95
balanceNodeFunction · 0.90
walkNodesFunction · 0.90
getLeafOrderFunction · 0.85

Tested by

no test coverage detected