2.1.1 • Published 4 years ago

@danieldyachenko/debounce v2.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

debounce

GitHub Logo

A decorator or higher-order function to prevent repeated calls during the transmitted period of time. Automatically bind this. Returns a promise.

npm version

Table of Contents

Quick start

Install

npm i @danieldyachenko/debounce

Usage

Can be used in two ways:

Decorator

import debounce from '@danieldyachenko/debounce';

class Api {
  
  @debounce(500)
  requestMethod() {
    // do something
  };
}

Or you can return the promise:

import debounce from '@danieldyachenko/debounce';

class Api {
  
  @debounce(500)
  requestMethod() {
    return Promise.resolve('result');
  };
}

const api = new Api();
api.requestMethod().then(res => console.log(res)) // => result

Higher order function

import debounce from '@danieldyachenko/debounce';

const debouncedFn = debounce(500, (arg) => console.log(arg));
debouncedFn('your argument'); // => your argument

Or you can return the promise:

import debounce from '@danieldyachenko/debounce';

const debouncedFn = debounce(500, (arg) => Promise.resolve(arg));
debouncedFn('your argument').then((res) => console.log(res)); // => your argument

Methods

debounce

Params

  • ms
    • Type: number
    • Description: time out, after which fn will call
  • fn
    • Type: function
    • Description: function that will be called after ms

Returns

  • Promise

Author

danieldyachenko

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago