When invoking the searchkeyword function on keyUp, my goal is to prevent or clear the timeout of $emit when a new letter is quickly typed. This way, I only want $emit to be called a few times. However, currently, the console triggers debounce on every searchkeyword call.
methods: {
searchKeyword : function() {
var scope = this;
(this.debounce(function(){
scope.$emit("search-keyword", scope.keyword);
console.log("Called");
},350))();
},
debounce: function (func, delay) {
var timeout;
return function() {
const context = this;
const args = arguments;
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(context, args), delay);
}
}
}