Primitives / foldkit-primitives/state

Pagination

const · packages/primitives/src/state/pagination.ts:41

Args{ perPage: number, total?: number | null }
Model{ page: number, perPage: number, total: number | null }
MessagesGoToPage { page: number }, NextPage, PrevPage, SetPerPage { perPage: number }, SetTotal { total: number | null }
Its full type
const Pagination: Bundle.Bundle<
  'Pagination',
  { readonly perPage: number; readonly total?: number | null | undefined },
  {
    readonly page: number
    readonly perPage: number
    readonly total: number | null
  },
  | { readonly _tag: 'GoToPage'; readonly page: number }
  | { readonly _tag: 'NextPage' }
  | { readonly _tag: 'PrevPage' }
  | { readonly _tag: 'SetPerPage'; readonly perPage: number }
  | { readonly _tag: 'SetTotal'; readonly total: number | null },
  never,
  never,
  never,
  void,
  {},
  {}
>

Pagination as a bundle: the page, page size, and total live in the Model, so page changes replay and every transition clamps into range. Pure logic, no streams: data loading stays the application's job.

In the guides