biofriction-wp-theme/node_modules/just-debounce
jorge-vitrubio a7910c81a8 moved to new repo 2021-10-26 14:18:09 +02:00
..
.eslintrc moved to new repo 2021-10-26 14:18:09 +02:00
.travis.yml moved to new repo 2021-10-26 14:18:09 +02:00
LICENSE moved to new repo 2021-10-26 14:18:09 +02:00
README.md moved to new repo 2021-10-26 14:18:09 +02:00
index.d.ts moved to new repo 2021-10-26 14:18:09 +02:00
index.js moved to new repo 2021-10-26 14:18:09 +02:00
package.json moved to new repo 2021-10-26 14:18:09 +02:00
prettier.config.js moved to new repo 2021-10-26 14:18:09 +02:00
test.js moved to new repo 2021-10-26 14:18:09 +02:00

README.md

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