2.1.1 • Published 4 years ago
@danieldyachenko/debounce v2.1.1
debounce
A decorator or higher-order function to prevent repeated calls during the transmitted period of time. Automatically bind this. Returns a promise.
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
- Type:
fn
- Type:
function
- Description: function that will be called after ms
- Type:
Returns
Promise
Author
danieldyachenko