Skip to main content
Version: v10.0.0

InfiniteQuery

A window over an ordered live query: the first pageSize times the number of pages rows of its result. Widening it shows rows the db holds at once and loads more from the query's loader only when the window runs past them.

The window belongs to this instance, so two components showing the same query share its live query and its subset, and each keeps its own number of pages.


Import
import { InfiniteQuery } from "@hyper-fetch/db"

Parameters​

class InfiniteQuery<Item> {
constructor(runtime: DbRuntime, definition: QueryDefinition, options: InfiniteQueryOptions) {};
key: string;
fetchNextPage() => Promise<void>;
getSnapshot() => InfiniteQueryState<Item>;
refetch() => Promise<void>;
subscribe(listener: () => void) => () => void;
}
Parameters
NameTypeDescription
runtime
DbRuntime
definition
QueryDefinition
options
InfiniteQueryOptions

Properties​

key​

Identifies the infinite query by its query's structure and page size

Type
string

Methods​

fetchNextPage()​

Widens the window by one page. Rows the db holds show at once, and the loader loads more when the window runs past them. Resolves once the window is filled or the backend has no more rows.

Preview
fetchNextPage()
Returns
Promise<void>

getSnapshot()​

Preview
getSnapshot()
Returns
getSnapshot
NameTypeDescription
data
Data | undefined

undefined until the query has loaded, then the selected fields of every row

error
unknown

The last failure, also when a refresh failed and the rows stay

hasNextPage
boolean

Whether a paginated query has another page

isFetching
boolean

Whether a request for the query is in flight

stale
boolean

Whether the rows may be out of date: their subset is stale or its syncs are disconnected

status
QueryStatus

error only when a first load failed and there is nothing to show

isFetchingNextPage
boolean

Whether more rows are loading to fill the window after fetchNextPage

pages
Item[][]

data split into pages of pageSize


refetch()​

Loads the query again from its first page

Preview
refetch()
Returns
Promise<void>

subscribe()​

Preview
subscribe(listener: () => void)
Parameters
Parameters
NameTypeDescription
listener
() => void
Returns
() => void