simple-lazy-debounce

0.0.17 • Public • Published

Simple Lazy Debounce

Simple Lazy Debounce is a lightweight JavaScript library that provides a simple way to debounce function calls.

If a function call is made within the defaultDelay time, the delay is incremented by latencyIncrement, up to the value of maxDelay. For example, if there were 5 calls every 100 ms, the function would be executed once at 1001 ms.

Installation

You can install Simple Lazy Debounce using npm:

npm install simple-lazy-debounce

Usage

import { SimpleLazyDebounce } from "simple-lazy-debounce";

const doSomething = SimpleLazyDebounce(
  // your callback function
  () => {
    console.log("Do something!");
  },
  // options
  {
    defaultDelay: 300, // ms
    maxDelay: 500, // ms
    latencyIncrement: 100, // ms
  },
);

setTimeout(() => {
  doSomething();
}, 100);

setTimeout(() => {
  doSomething();
}, 200);

setTimeout(() => {
  doSomething();
}, 300);

setTimeout(() => {
  doSomething();
}, 400);

setTimeout(() => {
  doSomething();
}, 500);

// Executed once at 1001 ms
// console output: Do something!

Package Sidebar

Install

npm i simple-lazy-debounce

Weekly Downloads

115

Version

0.0.17

License

MIT

Unpacked Size

5.25 kB

Total Files

6

Last publish

Collaborators

  • youngho.jeon.korea