UNPKG

@cc-heart/utils

Version:

🔧 javascript common tools collection

40 lines (39 loc) • 1.78 kB
import type { Fn } from '../typings/helper'; interface CacheResultFunc { _result?: any; (...args: any): any; } interface DefineDebounceFn { (fn: CacheResultFunc, delay?: number, immediate?: boolean): ReturnType<CacheResultFunc>; } /** * DefineDebounceFn is a function that creates a debounced function. * @param fn - The function to be debounced. * @param delay - The delay in milliseconds to wait before the debounced function is called. Default is 500ms. * @param immediate - Whether the debounced function should be called immediately before the delay. Default is false. * @returns - The debounce function. */ export declare const defineDebounceFn: DefineDebounceFn; /** * Creates a function that can only be called once. * * @param fn - The function to be called once. * @returns - A new function that can only be called once. */ export declare function defineOnceFn<T>(fn: (...args: any) => T): (this: any, ...args: any) => T; /** * defineThrottleFn is a function that creates a throttled function. * @param - The function to be throttled. * @param - The delay in milliseconds to wait before the throttled function is called. Default is 500ms. * @returns - The throttled function. */ export declare function defineThrottleFn(fn: Fn, delay?: number): CacheResultFunc; /** * defineSinglePromiseFn ensures that the provided function can only be called once at a time. * If the function is invoked while it's still executing, it returns the same promise, avoiding multiple calls. * * @param fn - The function to be wrapped, which returns a promise. * @returns A function that ensures the provided function is only executed once and returns a promise. */ export declare function defineSinglePromiseFn(fn: Fn): () => Promise<any>; export {};