Socket
Socket
Sign inDemoInstall

just-debounce

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    just-debounce

a simple debounce with no dependencies or crazy defaults


Version published
Weekly downloads
1.1M
increased by0.43%
Maintainers
1
Install size
8.18 kB
Created
Weekly downloads
 

Readme

Source

just-debounce

just a basic debounce function

changes

  • 1.1.0: added typescript definitions

Why?

I searched npm and the first 3 pages of results for "debounce" did not have a small correctly implemented version of debounce

Usage

arguments

  • fn: the function to debounce
  • delay: debounce delay in ms
  • atStart: if true, the function will be called at the beginning of the delay rather than the end
  • guarantee: additional calls to debounced function will not reset they delay. This guarantees that if the function is called frequently, it will fire once every delay rather than waiting for a break in calls.
var db = require('just-debounce');

var debounced = db(function (v) {
  console.log(v);
}, 100);

debounced('hi');
debounced('hi');
// logs 'hi' once after 100ms
var db = require('just-debounce');

var debounced = db(
  function (v) {
    console.log(v);
  },
  100,
  true
);

debounced('hi');
debounced('hi');
// logs 'hi' once right away, but not a second time. calling after 100ms will log again
var db = require('just-debounce');

var debounced = db(
  function (v) {
    console.log(v);
  },
  100,
  false,
  true
);

debounced('hi');
setTimeout(function () {
  debounced('hi2');
}, 80);

// logs 'hi2' once 100ms after the first call to debounced

license

MIT

Keywords

FAQs

Last updated on 17 Feb 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc