Repository navigation
Adds createPager(), which holds the page a screen shows, and truncated on what paginate returns, which tells a walk that maxPages cut short from one that finished.
Added
createPager(endpoint, params, options)holds the page a screen shows, moves it, and keeps a frozenstatethat a UI subscribes to. It takes anycreateApiendpoint orcreateGraphQLoperation.toParamsmakes a numbered pager, wheregoTo(page)opens any page;nextmakes a cursor pager, with Previous through the pages already seen, andfromandprevfor a cursor kept in the address; addingitemsto either makes one growing list for infinite scroll, whichrestorebrings back after a reload. Pages already shown come back from a cache without a request, andsetParamsstarts again at page 1 for a filter change. Creating a pager sends nothing, and it never throws (createPager(), Pagination).- The latest move wins, per pager. A move cancels the request the same pager started for the move before it, and a reply that arrives anyway never changes the state. The overtaken move resolves with
kind: 'abort'. Only the pager's own requests are cancelled: two pagers over one endpoint, apaginatewalk and a plain call never cancel each other, and withshare: truean overtaken move leaves only the pager's part of the shared request. truncatedon whatpaginatereturns. Once the loop has ended,pages.truncatedistruewhenmaxPagesstopped the walk and yournextsays there was another page, andfalsewhen the pages ran out, an error page ended it, or the cap landed on the last page. It sends no request: it calls yournextonce, on the first read, and remembers the answer (When to stop).- New exports:
createPager, and the typesPager,PagerState,PagerOptions,NumberedPagerOptions,CursorPagerOptions,ListOptions,PagerBaseOptionsandPages.paginatenow returnsPages<R>, a subtype of the async generator it returned before, so existing code compiles unchanged.
Documentation
- Pagination has the pager: a numbered pager, Previous and Next over cursors, infinite scroll that restores, GraphQL, React, Vue and Svelte wrappers, and what happens when a reply arrives late. The reference page lists every option, every field of the state, every method and every way a move resolves. The playground has a pager example.
Sizes, gzipped: a REST-only import is 7.0 kB and 9.4 kB with poll and pollUntil, both unchanged, because the pager is left out of any bundle that doesn't import it. Importing createPager makes REST plus the pager 9.9 kB. The core entry is 13.7 kB (was 11.4 kB), and 15.0 kB with all the middleware (was 12.7 kB).