update debounce function

This commit is contained in:
Victor Amorim 2024-02-14 14:01:15 -03:00
parent 2ecb6d69b4
commit 801f5eba7b
No known key found for this signature in database
GPG key ID: F251892F5DD5F65D

View file

@ -17,21 +17,15 @@ function toggleByID(id) {
}
}
//http://davidwalsh.name/javascript-debounce-function
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
function debounce(func, delay) {
let timer;
return function(...args) {
clearTimeout(timer);
timer = setTimeout(() => {
func.apply(this, args);
}, delay);
};
};
}
$('#filter').on("keyup", debounce(filter, 500));