typescript-debounce-decorator
v0.0.18
Published
A debounce decorator for typescript class method
Downloads
17,763
Maintainers
Readme
typescript-debounce-decorator
A debounce decorator for typescript class method
- Tiny (1KB after uglify compressed)
- No dependency
- Easy to use
Install
npm install typescript-debounce-decorator --save
Usage
Syntax:
@debounce(debounceTime, options)
Params:
- debounceTime:
number
Function execute interval in milliseconds. - options:
object
Options.- leading:
boolean
Should function invoke on the leading or trailing of the wait timeout.
- leading:
NOTE: Return value of function which applied debounce decorator will be eaten.
Basic usage:
import { debounce } from "typescript-debounce-decorator";
class Foo {
@debounce
bar() {
console.log("foobar");
}
}
With debounce time:
import { debounce } from "typescript-debounce-decorator";
class Foo {
@debounce(1000)
bar() {
console.log("foobar");
}
}
With options:
import { debounce } from "typescript-debounce-decorator";
class Foo {
@debounce(1000, { leading: true })
bar() {
console.log("foobar");
}
}
Cancel:
import { debounce, cancel } from "typescript-debounce-decorator";
class Foo {
@debounce(1000, { leading: true })
bar() {
console.log("foobar");
}
cancel() {
cancel(this.bar);
}
}
Changelog
- 0.0.18: [BREAKCHANGE] leading option now default to false
License
MIT