Created
March 27, 2017 13:52
-
-
Save rla/6c51a69041ec1c4ab8beeefd69aae1dc to your computer and use it in GitHub Desktop.
Debounce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assert = require('assert'); | |
// Helper to debounce function calls. | |
module.exports = (time, fn) => { | |
assert.equal(typeof time, 'number'); | |
assert.equal(typeof fn, 'function'); | |
let debounce = false; | |
return function() { | |
if (debounce) { | |
return; | |
} | |
debounce = true; | |
setTimeout(() => { | |
debounce = false; | |
}, time); | |
fn.call(this); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment