Debounce Tools is a TypeScript library for debouncing function calls in both synchronous and asynchronous contexts.
To install Debounce Tools, you can use NPM:
npm install @frankykubo/debounce-tools
Here are the available functions in Debounce Tools:
Function | Parameters | Description |
---|---|---|
debounceMemoize |
callback: (...args: any[], prevArgs: any[][] = []) => any , delay: number |
Async function that debounces and memoizes the result of the callback function |
syncDebounceMemoize |
callback: (...args: any[], prevArgs: any[][] = []) => void , delay: number |
Sync function that debounces and memoizes the result of the callback function |
import { debounceMemoize } from '@frankykubo/debounce-tools';
const printStr = (someString: string, prevArgs: string[][] = []) => {
console.log(someString);
console.log(prevArgs.flatMap(str => str));
}
const printStrWrapped = debounceMemoize(printStr, 100);
printStrWrapped('Test');
printStrWrapped('debounced');
printStrWrapped('printStr');
printStrWrapped('function');
$ 'function'
$ [ 'Test', 'debounced', 'printStr' ]
import { syncDebounceMemoize } from '@frankykubo/debounce-tools';
const printStr = (someString: string, prevArgs: string[][] = []) => {
console.log(someString);
console.log(prevArgs.flatMap(str => str));
return someString;
}
const printStrWrapped = syncDebounceMemoize(printStr, 100);
printStrWrapped('Test');
printStrWrapped('debounced');
printStrWrapped('printStr');
printStrWrapped('function');
$ 'function'
$ [ 'Test', 'debounced', 'printStr' ]
Contributions are welcome! Please feel free to open issues and pull requests on GitHub.
This project is licensed under the MIT License.