@helper-modules/debounce

1.0.1 • Public • Published

@helper-modules/debounce

Allows to debounce function calls.

Installation

npm i @helper-modules/debounce

Usage

Syntex

debounce(callback: Function, delay: Number);
  • Params:
    • callback:
      • type: Function
      • default: undefined
      • usage: Callback that will debounce
    • delay:
      • type: Number
      • default: undefined
      • usage: Delay in milliseconds

Example

  • This function helps a lot when you are calling some function lots of time but you only need to call it when it should be called.

  • Like when user is typing in a input box and you want to make it so that when user stops typing for a while, you send a request to the server for some data fetching.

const debounce = require("@helper-modules/debounce");

const callback = (msg) => {
    console.log(msg);
}

const debouncedCallback = debounce(callback, 2000);

let interval = setInterval(() => {
    console.log("interval");
    debouncedCallback("callback called");
}, 500);

setTimeout(() => {
    console.log("clearing interval")
    clearInterval(interval);
}, 3000);

example

Readme

Keywords

Package Sidebar

Install

npm i @helper-modules/debounce

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

3.65 kB

Total Files

6

Last publish

Collaborators

  • helper-modules