MCPcopy Create free account
hub / github.com/bvaughn/react-window / get

Function get

lib/core/createCachedBounds.ts:17–57  ·  view source on GitHub ↗
(index: number)

Source from the content-addressed store, hash-verified

15 return {
16 itemSize: typeof itemSize === "number" ? itemSize : undefined,
17 get(index: number) {
18 assert(index < itemCount, `Invalid index ${index}`);
19
20 if (typeof itemSize === "number") {
21 assert(index >= 0, `Invalid index ${index}`);
22 return { size: itemSize, scrollOffset: index * itemSize };
23 }
24
25 while (cache.size - 1 < index) {
26 const currentIndex = cache.size;
27
28 const size = itemSize(currentIndex, itemProps);
29
30 if (currentIndex === 0) {
31 cache.set(currentIndex, {
32 size,
33 scrollOffset: 0
34 });
35 } else {
36 const previousRowBounds = cache.get(currentIndex - 1);
37 assert(
38 previousRowBounds !== undefined,
39 `Unexpected bounds cache miss for index ${index}`
40 );
41
42 cache.set(currentIndex, {
43 scrollOffset:
44 previousRowBounds.scrollOffset + previousRowBounds.size,
45 size
46 });
47 }
48 }
49
50 const bounds = cache.get(index);
51 assert(
52 bounds !== undefined,
53 `Unexpected bounds cache miss for index ${index}`
54 );
55
56 return bounds;
57 },
58 set(index: number, bounds: Bounds) {
59 cache.set(index, bounds);
60 },

Callers

nothing calls this directly

Calls 2

assertFunction · 0.90
itemSizeFunction · 0.70

Tested by

no test coverage detected