paginate
Collects every item of a paginated source by requesting pages one after the other, from page 1, until the source runs out.
It stops after a page that is null, empty, or shorter than pageSize, or once maxPages
pages were requested. A null page is not added to the result. A rejection from
fetchPage rejects the whole call, and the items already collected are lost.
Without maxPages, a source that never returns a short or empty page is requested forever,
so set one for an API you do not control, or a signal to stop it.
Available since v3.1.5
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
fetchPage | function | Returns the items of a page, given its 1-based number, or `null` for no data |
options | PaginateOptions | Page size, page limit and cancellation — see PaginateOptions |
Returns
Section titled “Returns”Promise<T[]> — All the items, in page order
Examples
Section titled “Examples”Collect every page
Section titled “Collect every page”Pages are requested in order until one is shorter than pageSize.
Cap the number of pages
Section titled “Cap the number of pages”maxPages protects against a source that never runs out.
Related Types
Section titled “Related Types”PaginateOptions
Section titled “PaginateOptions”Options for paginate.
