Skip to content

Latest commit

 

History

History
96 lines (62 loc) · 1.7 KB

README.md

File metadata and controls

96 lines (62 loc) · 1.7 KB

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