import type { Inputs, PromiseStatus } from "../dependencies/types"; import type { Fetch, Name, NevoProps, NevoPropsReadonly, Select, Subscribe, ValueMutator } from "../types"; type AsyncPropsOptions = { value?: (name: Name) => Q | undefined; onChange?: (value: T, name?: Name) => Q; handle: Fetch; subscribe?: Subscribe; props?: NevosProps; }; type AsyncPropsResult = NevoProps & { status: PromiseStatus; onAbort: () => void; onRefresh: () => void; }; /** * Properties according to the NEVO pattern, where the `value` sets the initial value of the returned `value`. Optionally supports `status` and `onChangeStatus` for tracking `status` updates. */ type NevosProps = NevoProps & { status?: PromiseStatus; onChangeStatus?: ValueMutator; }; /** * Asynchronously handles getting the `value` and its `onChange`s by `handle`ing queries and `subscribing` to updates. * * If `options.value(name)` is set, uses the defined return value (a "query") and passes it to `options.handle(query)`. If `options.value(name)` returns an undefined value, nothing happens. * * If `options.onChange(value, name)` is set, uses the defined return value (a "query") and passes it to `options.handle(query)`. If `options.onChange(value, name)` returns an undefined value, nothing happens. * * The `options.handle(query)` function returns asynchronously (or, if needed, synchronously) a `value` that gets returned in the result. * * Asynchronous tasks can be tracked with the returned `status` property, and aborted using the returned `onAbort()` method. Ongoing operations are automatically aborted when the element that runs this hook unmounts. * * The asynchronous task that gets the `value` can be re-executed using the returned `onRefresh()` method. * * If `options.subscribe(query, onRefresh)` is defined, it is called everytime a new `query` is returned by `options.value(name)`, and passed along with the `onRefresh(query)` method to trigger a refresh. The `onRefresh(query)` is called with a change query to ignore the queries that emanate from the element using this hook. The `options.subscribe(query, onRefresh)` function can return a function that gets called before a new `options.subcribe(query, onRefresh)` call is made or when the element unmounts, enabling unsubscription logic to happen. * * @param options Contains the optional `value` and `onChange` query builders, the required `handle(query)` method, the optional `subscribe(query, onRefresh)` method, and the optional parent props according to the NEVO pattern (with support for `status` and `onChangeStatus`). * @param dependencies List of values that, when changing, trigger a new asynchronous `value` loading task if `options.value(name)` is set, refresh the subscription if `options.subscribe(query, onRefresh)` is set, and update the definition of the returned `onChange` function. * @returns The properties according to the NEVO pattern, with the `status` of the ongoing task, and the `onRefresh()` and `onAbort()` methods. */ export declare function useAsyncProps(options: Select, "onChange", "props">, dependencies?: Inputs): Select, "onChange", never>; export declare function useAsyncProps(options: Select, never, "onChange" | "props"> & { props: NevoPropsReadonly; }, dependencies?: Inputs): Select, never, "onChange">; export declare function useAsyncProps(options: Select, never, "onChange" | "props">, dependencies?: Inputs): Select, never, "onChange">; export declare function useAsyncProps(options: Select, "onChange", "props"> & { props: NevoPropsReadonly; }, dependencies?: Inputs): Select, "onChange", never>; export declare function useAsyncProps(options: Select, "props" | "onChange", never>, dependencies?: Inputs): Select, "onChange", never>; export declare function useAsyncProps(options: Select, "props", "onChange">, dependencies?: Inputs): AsyncPropsResult; export {};