@vdegenne/debouncer
v1.0.17
Published
```ts import {Debouncer} from '@vdegenne/debouncer';
Readme
@vdegenne/debouncer
Debouncer main utility class
import {Debouncer} from '@vdegenne/debouncer';
/* Target function */
function boom(arg: string) {
// do something
console.log(arg);
}
/* Definition */
const boomDebouncer = new Debouncer(boom, 1000); // 1s
boomDebouncer.debounce('foo');
boomDebouncer.debounce('bar'); // cancels previous, and prints "bar" after 1s
// d.cancel()Use boomDebouncer.cancel() to cancel any previous debounce.
Use boomDebouncer.call() to cancel any previous debounce and call the target function.
debounce utility function
import {debounce} from '@vdegenne/debouncer';
function boom(v: string) {
console.log(v);
}
debounce(boom, 1000)('foo');
debounce(boom, 2000)('bar'); // cancels previous and prints "bar" after 2snote: Only the function reference is used for distinct debounce, changing the timeout will not create a new debouncer.
