root 3bf41bf355 update | il y a 1 an | |
---|---|---|
.. | ||
.eslintrc | il y a 1 an | |
.npmignore | il y a 1 an | |
LICENSE | il y a 1 an | |
README.md | il y a 1 an | |
index.js | il y a 1 an | |
package.json | il y a 1 an | |
test.js | il y a 1 an |
just a basic debounce function
I 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 msat_start:
if true, the function will be called at the beginning of the
delay rather than the endguarantee
: ensures the time before the next call the fn
is not greater \
than the delay period.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