typescript-debounce-decorator
v0.0.18
Published
A debounce decorator for typescript class method
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 --saveUsage
Syntax:
@debounce(debounceTime, options)Params:
- debounceTime:
numberFunction execute interval in milliseconds. - options:
objectOptions.- leading:
booleanShould 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
