Tiny debounce for Vue.js
Published in
1 min readJun 16, 2017
tip#27
For a mobile project, I was using lodash.debounce, but it has 370 lines of code for something that I could do in 10.
So I created tiny-debounce.
The code is just 11 lines and look like this:
module.exports = function debounce (fn, delay) {
var timeoutID = null
return function () {
clearTimeout(timeoutID)
var args = arguments
var that = this
timeoutID = setTimeout(function () {
fn.apply(that, args)
}, delay)
}
}
You can learn more about what debounce does in this article.