1.0.4 • Published 6 years ago

debounce-decorator-ts v1.0.4

Weekly downloads
148
License
MIT
Repository
github
Last release
6 years ago

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