shelving
Version:
Toolkit for using data in JavaScript.
22 lines (21 loc) • 1.36 kB
TypeScript
import type { NONE } from "../util/constants.js";
import { FetchStore } from "./FetchStore.js";
import { type AsyncStoreInput, Store } from "./Store.js";
export type PayloadFetchCallback<P, R> = (payload: P, signal: AbortSignal) => AsyncStoreInput<R>;
/**
* Store that fetches its values from a remote source by sending a payload to them.
*
* @param payload The initial payload for the store.
* @param value The initial value for the store, or `NONE` if it does not have one yet.
* @param callback An optional callback that, if set, will be called with the current payload when the `fetch()` method is invoked to fetch the next value.
* @param debounce Delay in milliseconds before the fetch is triggered after a payload change. `busy` becomes `true` immediately; the actual fetch waits for the debounce period to expire. If the payload changes again before the delay expires the previous fetch is cancelled and the timer resets.
*/
export declare class PayloadFetchStore<P, R> extends FetchStore<R> {
/**
* Store keeping the current payload to send to the fetch on send.
* - New payloads can be set using `this.payload.value`
*/
readonly payload: Store<P>;
constructor(payload: P | typeof NONE, value: R | typeof NONE, callback?: PayloadFetchCallback<P, R>, debounce?: number);
[Symbol.asyncDispose](): Promise<void>;
}