swr-global-state
Version:
Zero-setup & simple global state management for React Components
40 lines • 1.6 kB
TypeScript
import type { Key } from "swr";
export type RateLimitType = 'debounce' | 'throttle';
export type RateLimitConfig<T> = {
type: RateLimitType;
delay: number;
customFunction?: (func: (key: Key, data: T) => Promise<void>, delay: number) => (key: Key, data: T) => void;
};
/**
* Enhanced debounce utility function with cleanup
* @param func Function to debounce
* @param delay Delay in milliseconds
* @returns Object with debounced function and cleanup
*/
export declare function debounceWithCleanup<T extends (...args: any[]) => any>(func: T, delay: number): {
debouncedFunc: T;
cleanup: () => void;
};
/**
* Enhanced throttle utility function with cleanup
* @param func Function to throttle
* @param delay Delay in milliseconds
* @returns Object with throttled function and cleanup
*/
export declare function throttleWithCleanup<T extends (...args: any[]) => any>(func: T, delay: number): {
throttledFunc: T;
cleanup: () => void;
};
/**
* Enhanced rate limited function creator with cleanup
* @param func Function to rate limit
* @param config Rate limit configuration
* @param onStart Optional callback when rate limited function starts
* @param onEnd Optional callback when rate limited function ends
* @returns Object with rate limited function and cleanup
*/
export declare function createRateLimitedFunctionWithCleanup<T>(func: (key: Key, data: T) => Promise<void>, config: RateLimitConfig<T>, onStart?: () => void, onEnd?: () => void): {
rateLimitedFunc: (key: Key, data: T) => void;
cleanup: () => void;
};
//# sourceMappingURL=utils.d.ts.map