UNPKG

stream-chat

Version:

JS SDK for the Stream Chat API

70 lines (69 loc) 2.4 kB
import { StateStore } from '../store'; import { type DebouncedFunc } from '../utils'; type PaginationDirection = 'next' | 'prev'; type Cursor = { next: string | null; prev: string | null; }; export type PaginationQueryParams = { direction: PaginationDirection; }; export type PaginationQueryReturnValue<T> = { items: T[]; } & { next?: string; prev?: string; }; export type PaginatorDebounceOptions = { debounceMs: number; }; type DebouncedExecQueryFunction = DebouncedFunc<(params: { direction: PaginationDirection; }) => Promise<void>>; export type PaginatorState<T = any> = { hasNext: boolean; hasPrev: boolean; isLoading: boolean; items: T[] | undefined; lastQueryError?: Error; cursor?: Cursor; offset?: number; }; export type PaginatorOptions = { /** The number of milliseconds to debounce the search query. The default interval is 300ms. */ debounceMs?: number; pageSize?: number; }; export declare const DEFAULT_PAGINATION_OPTIONS: Required<PaginatorOptions>; export declare abstract class BasePaginator<T> { state: StateStore<PaginatorState<T>>; pageSize: number; protected _executeQueryDebounced: DebouncedExecQueryFunction; protected _isCursorPagination: boolean; protected constructor(options?: PaginatorOptions); get lastQueryError(): Error | undefined; get hasNext(): boolean; get hasPrev(): boolean; get hasResults(): boolean; get isLoading(): boolean; get initialState(): PaginatorState; get items(): T[] | undefined; get cursor(): Cursor | undefined; get offset(): number | undefined; abstract query(params: PaginationQueryParams): Promise<PaginationQueryReturnValue<T>>; abstract filterQueryResults(items: T[]): T[] | Promise<T[]>; setDebounceOptions: ({ debounceMs }: PaginatorDebounceOptions) => void; canExecuteQuery: (direction: PaginationDirection) => boolean; protected getStateBeforeFirstQuery(): PaginatorState<T>; protected getStateAfterQuery(stateUpdate: Partial<PaginatorState<T>>, isFirstPage: boolean): PaginatorState<T>; executeQuery({ direction }: { direction: PaginationDirection; }): Promise<void>; cancelScheduledQuery(): void; resetState(): void; next: () => Promise<void>; prev: () => Promise<void>; nextDebounced: () => void; prevDebounced: () => void; } export {};