MCPcopy Create free account
hub / github.com/adobe/react-spectrum / countItems

Function countItems

packages/react-stately/src/collections/getItemCount.ts:26–34  ·  view source on GitHub ↗
(items: Iterable<Node<T>>)

Source from the content-addressed store, hash-verified

24 // TS isn't smart enough to know we've ensured count is a number, so use a new variable
25 let counter = 0;
26 let countItems = (items: Iterable<Node<T>>) => {
27 for (let item of items) {
28 if (item.type === 'section') {
29 countItems(getChildNodes(item, collection));
30 } else if (item.type === 'item') {
31 counter++;
32 }
33 }
34 };
35
36 countItems(collection);
37 cache.set(collection, counter);

Callers 1

getItemCountFunction · 0.85

Calls 1

getChildNodesFunction · 0.90

Tested by

no test coverage detected