Simple function debounce decorator written in Typescript.
- Has no dependencies.
- Very tiny < 1kb
- Very easy to use
An live example of function use: Live Example
Install package by npm
npm install --save-dev debounce-decorator-ts
SYNTAX
@debounceFn(debounceTime, timeoutPropertyName);
Properties
-
debounceTime
Action: Setting debounceTimer
Default value:100
(ms)
Argument type: number ( miliseconds ) -
timeoutPropertyName
Action: Setting timeout property name ( for clearTimeout )
Default value:'timeoutFn'
Argument type: string
Basic usage
import { debounceFn } from "debounce-decorator-ts";
class MyClass {
constructor() {
window.addEventListener('resize', this.onResizeFn.bind(this));
}
@debounceFn()
private onResizeFn(e: Event): void {
console.log('resized!');
}
}
const myClass = new MyClass;
Override default properties value
import { debounceFn } from "debounce-decorator-ts";
class MyClass {
constructor() {
window.addEventListener('resize', this.onResizeFn.bind(this));
}
@debounceFn(1000, 'myCustomTimeoutPropertyName')
private onResizeFn(e: Event): void {
console.log('resized!');
}
}
const myClass = new MyClass;
MIT License