You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fangdawei
ef5e3ecfd0
|
1 year ago | |
---|---|---|
.. | ||
.eslintrc | 1 year ago | |
.travis.yml | 1 year ago | |
LICENSE | 1 year ago | |
README.md | 1 year ago | |
index.d.ts | 1 year ago | |
index.js | 1 year ago | |
package.json | 1 year ago | |
prettier.config.js | 1 year ago | |
test.js | 1 year ago |
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 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 theydelay
. This guarantees that if the function is called frequently, it will fire once everydelay
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