Function: debounce()
debounce<
T>(function_: (...arguments_:T) =>void,wait:number): (...arguments_:T) =>void
Defined in: src/stores/utils.ts:129
Debounce utility for store actions with automatic cleanup.
Type Parametersโ
Tโ
T extends unknown[]
Parametersโ
function_โ
(...arguments_: T) => void
Function to debounce
waitโ
number
Wait time in milliseconds before executing
Returnsโ
Debounced version of the input function
(...
arguments_:T):void
Parametersโ
arguments_โ
...T
Returnsโ
void
Remarksโ
This utility prevents rapid successive calls to expensive operations like API requests or state updates. It uses a Map to track timeouts per unique argument combination, allowing different argument sets to be debounced independently.
Warning: This function creates timeouts that may not be cleaned up automatically. If used in components, ensure proper cleanup on unmount to prevent memory leaks. Consider using a proper cleanup mechanism in your component lifecycle.
Exampleโ
const debouncedSave = debounce(saveSettings, 500);
debouncedSave(newSettings); // Will only execute after 500ms of no new calls