@jsvision/datagrid / windowedView
Function: windowedView()
windowedView<
T>(source):T[]
Defined in: datagrid/src/windowing.ts:103
A length-correct, lazily-read view over a windowed source, presentable as the display: () => T[] the grid body demands. .length reports the source total; an integer index returns the loaded row or undefined (a hole is never collapsed away). It is typed T[], but only .length and integer indexing are supported — every whole-array operation (.map/.find/.reduce/spread/for..of) throws a descriptive error, because such an operation over a windowed source would either crash on the first unloaded row or full-scan the entire dataset (a fetch-storm). Route each whole-array consumer behind isWindowed and read source.rowAt(i) directly instead.
Type Parameters
T
T
Parameters
source
The windowed source to present as a lazy array.
Returns
T[]
A T[]-typed lazy view: length-correct, integer-indexable, and fail-loud on any other access.
Example
import { windowedView } from '@jsvision/datagrid';
import type { GridDataSource } from '@jsvision/datagrid';
interface Row { id: number; name: string }
const loaded = new Map<number, Row>();
for (let i = 0; i < 50; i++) loaded.set(i, { id: i, name: `Row ${i}` });
const source: GridDataSource<Row> = {
rowKey: (r) => r.id,
length: () => 100000,
rowAt: (i) => loaded.get(i),
ensureRange: (start, end) => {
// fetch rows [start, end) from the backing store and populate `loaded`
},
};
const view = windowedView(source); // source.length() === 100000, only rows [0,50) loaded
view.length; // 100000 (the source total)
view[10]; // the loaded row
view[500]; // undefined (an unloaded hole)
// view.map(...) or [...view] throws — gate the consumer behind isWindowed(source) first.