Makes every list the API serves a page at a time work the same way. Each is a PagedList, whose next page useLoadMore appends, and this module reads its pages.

Functions

f
canLoadMore(list: PagedList<unknown> | null): boolean

Checks whether list has a next page to load now, which useLoadMore requires and useInfiniteScroll takes as enabled. A list not loaded yet is null.

f
firstPage<T>(
items: T[],
hasMore: boolean
): PagedList<T>

Returns the list holding only its first page, items.

f
mapItems<T>(fn: (items: T[]) => T[]): (list: PagedList<T>) => PagedList<T>

Returns a setter of a list's items as a setter of the list, for the sync hooks, which edit items only.

f
pageUrl(
url: string,
page: number,
limit?
): string

Returns url asking for page page, limit items long.

f
readFirstPage<T>(
res: Response,
deserialize: (wire: Wire<T>) => T
): Promise<PagedList<T>>

Returns the first page res answers as a list, or an empty list when the server refuses it. The profile pages read their lists with it beside the user, whose failure alone fails the page.

f
refetchPages<T extends { id: string; }>(
pages: number,
fetchPage: (page: number) => Promise<PaginatedData<T>>
): Promise<PaginatedData<T>>

Fetches pages 1 to pages of a list again, and resolves to their items, each once, and whether more follow. An item added between two pages' fetches shifts the later page by one, which would list an item twice. A live list calls it after a reconnection, through usePagedList's resync or, for the search's dumps, directly; it rejects when a page fails.

f
withByDate<T extends { id: string; createdAt: Date; }>(
items: T[],
item: T
): T[]

Returns items, newest first, with item where its createdAt puts it, as withInOrder does. useDumpListSync puts a new or newly visible dump in a list with it.

f
withFirst<T extends { id: string; }>(
items: T[],
item: T
): T[]

Returns items with item first, or items as they are when it is already there, as when a list's own echo of a new item arrives after it.

f
withInOrder<T extends { id: string; }>(
items: T[],
item: T,
compare: (
a: T,
b: T
) => number
): T[]

Returns items, in the order of compare as the API pages them, with item where that order puts it: before the first item that doesn't come before it. An item that comes after every one loaded is left to a later page, and items returned as they are, as they are when item is already there. usePlaylistListSync puts a new, newly visible or risen playlist in a list with it, whatever its order.

Interfaces

I
PagedList

Held for a list by usePagedList, or by a page that loads it along with more, as the search page does. useLoadMore loads the pages after page.