debounce-decorator-ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

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

Package Sidebar

Install

npm i debounce-decorator-ts

Weekly Downloads

80

Version

1.0.4

License

MIT

Unpacked Size

12.4 kB

Total Files

9

Last publish

Collaborators

  • zgrybus