MCPcopy Index your code
hub / github.com/adobe/react-spectrum / buildTree

Function buildTree

packages/react-stately/src/data/useTreeData.ts:166–189  ·  view source on GitHub ↗
(
    initialItems: T[] | null = [],
    map: Map<Key, TreeNode<T>>,
    parentKey?: Key | null
  )

Source from the content-addressed store, hash-verified

164 let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));
165
166 function buildTree(
167 initialItems: T[] | null = [],
168 map: Map<Key, TreeNode<T>>,
169 parentKey?: Key | null
170 ) {
171 if (initialItems == null) {
172 initialItems = [];
173 }
174 return {
175 items: initialItems.map(item => {
176 let node: TreeNode<T> = {
177 key: getKey(item),
178 parentKey: parentKey ?? null,
179 value: item,
180 children: null
181 };
182
183 node.children = buildTree(getChildren(item), map, node.key).items;
184 map.set(node.key, node);
185 return node;
186 }),
187 nodeMap: map
188 };
189 }
190
191 function updateTree(
192 items: TreeNode<T>[],

Callers 3

useTreeDataFunction · 0.85
insertFunction · 0.85
updateFunction · 0.85

Calls 3

getChildrenFunction · 0.85
getKeyFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected