1.0.1 • Published 4 years ago
@danieldyachenko/debounce v1.0.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/debounceUsage
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)) // => resultHigher order function
import debounce from '@danieldyachenko/debounce';
const debouncedFn = debounce(500, (arg) => console.log(arg));
debouncedFn('your argument'); // => your argumentOr 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 argumentMethods
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