Tiny debounce for Vue.js

Marcos Neves
vuejs-tips
Published in
1 min readJun 16, 2017

tip#27

https://github.com/vuejs-tips/tiny-debounce

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.

This is what it does.

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.

--

--

Marcos Neves
vuejs-tips

Ancient Brazilian web developer, from php, through Rails to Javascript, Vue.js enthusiast to React.