0.0.18 • Published 4 years ago

typescript-debounce-decorator v0.0.18

Weekly downloads
1,523
License
MIT
Repository
github
Last release
4 years ago

typescript-debounce-decorator

NPM version NPM downloads Build status

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.

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