Primitives / foldkit-primitives/state
Virtual
const · packages/primitives/src/state/virtual.ts:249
| Args | { gap: number, estimatedHeight: number, overscan: number, paddingStart: number, paddingEnd: number, initialScrollTop?: number, settleMs?: number, initialHeights?: { readonly [x: string]: number; } } |
|---|---|
| Model | { scrollTop: number, heights: { readonly [x: string]: number; }, scrolling: boolean, generation: number, estimatedHeight: number, overscan: number, gap: number, paddingStart: number, paddingEnd: number } |
| Messages | Settled { generation: number }, Measured { key: string, height: number }, Scrolled { top: number }, Prune { keys: readonly string[] } |
Its full type
const Virtual: Bundle.Bundle<
'Virtual',
{
readonly gap: number
readonly estimatedHeight: number
readonly overscan: number
readonly paddingStart: number
readonly paddingEnd: number
readonly initialScrollTop?: number | undefined
readonly settleMs?: number | undefined
readonly initialHeights?: { readonly [x: string]: number } | undefined
},
{
readonly scrollTop: number
readonly heights: { readonly [x: string]: number }
readonly scrolling: boolean
readonly generation: number
readonly estimatedHeight: number
readonly overscan: number
readonly gap: number
readonly paddingStart: number
readonly paddingEnd: number
},
| { readonly _tag: 'Settled'; readonly generation: number }
| { readonly _tag: 'Measured'; readonly key: string; readonly height: number }
| { readonly _tag: 'Scrolled'; readonly top: number }
| { readonly _tag: 'Prune'; readonly keys: readonly string[] },
never,
never,
never,
NoView,
{},
{},
undefined
>Windowing math for virtualized lists as pure functions: which rows to render, how tall the scrollable area is, and where each row starts. Row heights come from measured values with a per-row estimate fallback, so unmeasured rows still occupy space and measuring later only corrects. Keys are strings; heights are non-negative, and non-finite measurements fall back to the estimate instead of poisoning the sums.
The Virtual bundle below owns the scroll position and the measured
heights; Viewport reports container scrolls and MeasureRow reports
row heights, both as Mounts on the elements they observe. The application
renders windowFor(...) rows with its own views (keyed, so each
placements keep identity) inside a spacer of totalHeight(...).
In the guides
- Find a primitive by taskPrimitives / foldkit-primitives
- Subpaths by concernPrimitives / foldkit-primitives
- Rules every primitive keepsPrimitives / foldkit-primitives
- foldkit-primitives/statePrimitives / State
- Virtual: a windowed listPrimitives / State