import { Ref } from 'vue'; import { Any, Thing, Getter, Handler, Runner, WatchedRunner, AsyncCallback } from './types'; /** * Debounces a function call, so that it only runs after a certain amount of time has passed, * where the timer is reset each time the function is called, so repeated calls delay the * running of the function. * * @param id - A unique identifier for this debounce * @param runner - The function to run * @param wait - The time to wait before running the function */ export declare function debounce(id: string | symbol, runner: Runner, wait?: number): void; /** * Returns a debounced version of a function, with no need to specify an id. * * @param runner - The function to run * @param wait - The time to wait before running the function * @returns - A debounced version of the runner function */ export declare function debounced(runner: WatchedRunner, wait?: number): WatchedRunner; /** * Returns a WatchedRunner function Vue can watch() to see if it is currently running. * @param runner - The function to run * @returns - A WatchedRunner function */ export declare function watchRunner(runner: Runner): WatchedRunner; /** * Async function that resolves after a specified number of milliseconds. * * @param ms - The number of milliseconds to wait * @returns - A Promise that resolves after the specified time */ export declare function sleep(ms: number): Promise; export declare const WAITING: unique symbol; export declare const RESOLVED: unique symbol; export declare const CANCELLED: unique symbol; export declare const TIMED_OUT: unique symbol; export type WaitForStatus = { value?: typeof WAITING | typeof RESOLVED | typeof CANCELLED | typeof TIMED_OUT; }; export type CancellablePromise = Promise & { status: WaitForStatus; }; export type WaitForOptions = { eager?: boolean; every?: number; timeout?: number; }; /** * Checks the getter function repeatedly and only resolves function when it * returns a truthy result. It takes an options object with these props: * eager: true// tests immediately, not waiting for next tick * every: 100 // how long between checks * timeout: 0 // time to wait before rejecting, if <= 0, it will never reject * Returns a Promise that resolves with the result of the getter function. * The Promise has a status property that can be set to CANCELLED to reject it. * * @param getter - The function to call repeatedly, that gets the value being waited for * @param options - The options object * @returns - A Promise that resolves with the result of the getter function */ export declare function waitFor(getter: Getter, { eager, every, timeout }?: WaitForOptions): Promise; /** * This returns a Promise, like waitFor does, but requires a key/id to associate * it in a map, so that when called for the same key repeatedly, previous Promises * are cancelled and will reject at next check, instead of resolving. Thus, * calls to this should take care to catch cancellations. * * @param key - The unique key to associate with this waitFor * @param getter - The function to call repeatedly, that gets the value being waited for * @param options - The options object for waitFor */ export declare function waitForLast(key: string, getter: Getter, options?: WaitForOptions): Promise; /** * Returns a ref that is populated with the result of an async callback function. * This is useful for computed values that depend on async data. * * @param callback - The async function to call * @param defaultValue - Optional default value to use until the async function resolves * @returns A ref that will eventually be populated with the result of the async function */ export declare function asyncComputed(callback: AsyncCallback, defaultValue?: T): Ref; export declare function orArg(fn: Handler, arg: T): Any; /** * Returns a function that does nothing, but matches a signature and * by default, throws an error if it is called. * * @param throwOnExecution - If a string, throw an error with that message when called, if false, do nothing * @returns - A function that does nothing */ export declare function noop(throwOnExecution?: string | false): T;