Raxol.UI.Layout.StreamScrollContent (Raxol v2.6.0)

View Source

ScrollContent adapter for lazy/streaming data sources.

Takes a fetch function (offset, count) -> [element] and caches a sliding window of elements around the current scroll position. Enables viewport rendering of arbitrarily large datasets without materializing them all.

The total count must be known upfront (or estimated) for scrollbar rendering.

Summary

Functions

Fetches and caches a window of items, returning the requested slice.

Creates a new streaming scroll content source.

Types

t()

@type t() :: %Raxol.UI.Layout.StreamScrollContent{
  cache_items: [map()] | nil,
  cache_size: pos_integer(),
  cache_start: non_neg_integer() | nil,
  fetch_fn: (non_neg_integer(), pos_integer() -> [map()]),
  total: non_neg_integer()
}

Functions

fetch_and_update(state, offset, count)

@spec fetch_and_update(t(), non_neg_integer(), pos_integer()) :: {[map()], t()}

Fetches and caches a window of items, returning the requested slice.

Also returns the updated state with the new cache for the caller to store. Use fetch_and_update/3 if you need the updated state back.

new(opts)

@spec new(keyword()) :: t()

Creates a new streaming scroll content source.

Options

  • fetch_fn - fn offset, count -> [element] that retrieves a slice
  • total - total number of items (for scrollbar calculation)
  • cache_size - number of items to cache around the viewport (default: 100)