Skip to content

zgrybus/debounce-decorator-ts

Repository files navigation

DEBOUNCE-DECORATOR

ABOUT

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

Install package by npm

  npm install --save-dev debounce-decorator-ts

API

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

USAGE

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;

LICENSE

MIT License

About

Simple debounce decorator for functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published