MCPcopy Create free account
hub / github.com/bvaughn/react-virtualized / scanForUnloadedRanges

Function scanForUnloadedRanges

lib/components/InfiniteLoader/utils.ts:29–108  ·  view source on GitHub ↗
({
  isRowLoaded,
  minimumBatchSize,
  rowCount,
  startIndex,
  stopIndex
}: {
  isRowLoaded: InfiniteLoaderProps["isRowLoaded"];
  minimumBatchSize: number;
  rowCount: number;
  startIndex: number;
  stopIndex: number;
})

Source from the content-addressed store, hash-verified

27 * Returns all of the ranges within a larger range that contain unloaded rows.
28 */
29export function scanForUnloadedRanges({
30 isRowLoaded,
31 minimumBatchSize,
32 rowCount,
33 startIndex,
34 stopIndex
35}: {
36 isRowLoaded: InfiniteLoaderProps["isRowLoaded"];
37 minimumBatchSize: number;
38 rowCount: number;
39 startIndex: number;
40 stopIndex: number;
41}): IndexRange[] {
42 const unloadedRanges: IndexRange[] = [];
43
44 let rangeStartIndex: number | null = null;
45 let rangeStopIndex: number | null = null;
46
47 for (let index = startIndex; index <= stopIndex; index++) {
48 const loaded = isRowLoaded({ index });
49
50 if (!loaded) {
51 rangeStopIndex = index;
52 if (rangeStartIndex === null) {
53 rangeStartIndex = index;
54 }
55 } else if (rangeStopIndex !== null) {
56 unloadedRanges.push({
57 startIndex: rangeStartIndex!,
58 stopIndex: rangeStopIndex
59 });
60
61 rangeStartIndex = rangeStopIndex = null;
62 }
63 }
64
65 // If :rangeStopIndex is not null it means we haven't ran out of unloaded rows.
66 // Scan forward to try filling our :minimumBatchSize.
67 if (rangeStopIndex !== null) {
68 const potentialStopIndex = Math.min(
69 Math.max(rangeStopIndex, rangeStartIndex! + minimumBatchSize - 1),
70 rowCount - 1
71 );
72
73 for (let index = rangeStopIndex + 1; index <= potentialStopIndex; index++) {
74 if (!isRowLoaded({ index })) {
75 rangeStopIndex = index;
76 } else {
77 break;
78 }
79 }
80
81 unloadedRanges.push({
82 startIndex: rangeStartIndex!,
83 stopIndex: rangeStopIndex
84 });
85 }
86

Callers 2

InfiniteLoader.tsxFile · 0.90

Calls 1

isRowLoadedFunction · 0.70

Tested by

no test coverage detected