Tiny debounce for Vue.js

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.

Show your support

Clapping shows how much you appreciated Marcos Neves’s story.