Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
typescript-debounce
Advanced tools
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
or
yarn add typescript-debounce
Once the module has been installed, just import it and decorate any method:
import {Debounce} from 'typescript-debounce';
class MyClass {
@Debounce({millisecondsDelay: 1000})
public someMethod(arg1: string, arg2: number): void {
// ...
console.log('arg1: ', arg1, 'arg2:', arg2);
}
}
const instance = new MyClass();
instance.someMethod('a', 15);
// 300 ms later
instance.someMethod('foo', 42);
// after 1000 ms will display
// arg1: "foo" arg2: 42
Available options:
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 callAppendingArgumentsReducer
- 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 decoratedReducer 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> = (previousArgs: T[], newArgs: T[]) => T[]
FAQs
Debounce decorator for automatic function debouncing
The npm package typescript-debounce receives a total of 4 weekly downloads. As such, typescript-debounce popularity was classified as not popular.
We found that typescript-debounce demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.