seitu
Version:
28 lines • 1.09 kB
text/typescript
import { i as Subscribable, n as Readable } from "./index-B0IeflOl.mjs";
//#region src/core/debounced-fn/index.d.ts
interface DebouncedFn<F extends (...args: any[]) => any> extends Readable<ReturnType<F> | undefined>, Subscribable<ReturnType<F> | undefined> {
(...args: Parameters<F>): void;
cancel: () => void;
/** Run the pending call now. No-op if nothing is pending. */
flush: () => void;
pending: () => boolean;
}
/**
* Debounced callable that is also a subscribable. Each call resets the timer;
* the return value becomes the current state.
*
* @example
* ```ts twoslash
* import { createDebouncedFn } from 'seitu'
*
* const search = createDebouncedFn((query: string) => fetch(`/api?q=${query}`), 300)
* search.subscribe(result => console.log('result:', result))
* search('hello') // debounced — fires after 300ms of inactivity
* search.get()
* search.flush()
* search.cancel()
* ```
*/
declare function createDebouncedFn<F extends (...args: any[]) => any>(fn: F, wait: number): DebouncedFn<F>;
//#endregion
export { createDebouncedFn as n, DebouncedFn as t };