sensordb2 e64a8defe5 3.17 | 1 рік тому | |
---|---|---|
.. | ||
.eslintrc | 1 рік тому | |
.travis.yml | 1 рік тому | |
LICENSE | 1 рік тому | |
README.md | 1 рік тому | |
index.d.ts | 1 рік тому | |
index.js | 1 рік тому | |
package.json | 1 рік тому | |
prettier.config.js | 1 рік тому | |
test.js | 1 рік тому |
just a basic debounce function
1.1.0
: added typescript definitionsI searched npm and the first 3 pages of results for "debounce" did not have a small correctly implemented version of debounce
fn
: the function to debouncedelay
: debounce delay in msatStart:
if true, the function will be called at the beginning of the delay rather than the endguarantee
: 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
MIT