Debounce your method with a simple decoration
This module provides a decorator that enables you to debounce any typescript method. Specify delay in milliseconds. Any call to debounced method will be delayed by specified time amount. Should it be called before the timeout, timer will be reset and only the latest invocation will be executed.
Note: due to limitations, only void-returning functions may be debounced.
@DebouncePromise is to be implemented to handle returning functions debounce.
npm install --save typescript-debounce
yarn add typescript-debounce
Once the module has been installed, just import it and decorate any method:
;@public : void// ...console;
const instance = ;instance;// 300 ms laterinstance;// after 1000 ms will display// arg1: "foo" arg2: 42
millisecondsDelay- amount of time (in ms) that has to pass since last function call to actually invoke the debounced code
argumentsReducer(optional) - reducer function to handle multiple arguments lists passed in many calls; you may implement any reducer function manually, yet these are provided by this module:
OverridingArgumentsReducer(default, if none specified) - use only arguments from the last call
AppendingArgumentsReducer- append arguments of all subsequent method calls; since the actual arguments list lenght is arbitrary, the only sensible way to use it is when a function with "rest" argument is decorated
Reducer is a function that accepts two arguments, containing both previous and current arguments, and produces resulting arguments list. Its interface is as follows:ArgumentsReducer<T> = T