MCPcopy Create free account
hub / github.com/handsontable/handsontable / cloneTree

Method cloneTree

handsontable/src/utils/dataStructures/tree.ts:162–171  ·  view source on GitHub ↗

* @memberof TreeNode# * @function cloneTree * * Clones a tree structure deeply. * * For example, for giving a tree structure: * .--(B1)--. * .-(C1) .-(C2)-.----. * (D1) (D2) (D3) (D4) * * Cloning a tree starting from C2 node creates a mirrored tree struc

(nodeTree: TreeNode<T> = this)

Source from the content-addressed store, hash-verified

160 * @returns {TreeNode}
161 */
162 cloneTree(nodeTree: TreeNode<T> = this): TreeNode<T> {
163 // The spread of `T extends object` widens to a plain index type, so re-assert it as `T`.
164 const clonedNode = new TreeNode<T>({ ...nodeTree.data } as T);
165
166 for (let i = 0; i < nodeTree.childs.length; i++) {
167 clonedNode.addChild(this.cloneTree(nodeTree.childs[i]));
168 }
169
170 return clonedNode;
171 }
172
173 /**
174 * Replaces the current node with a passed tree structure.

Callers 2

tree.unit.tsFile · 0.80
collapseNodeFunction · 0.80

Calls 1

addChildMethod · 0.95

Tested by

no test coverage detected