Skip to content

Instantly share code, notes, and snippets.

@adamjgrant
Created May 20, 2020 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamjgrant/b408200c205779f79eb96ecfb95518f8 to your computer and use it in GitHub Desktop.
Save adamjgrant/b408200c205779f79eb96ecfb95518f8 to your computer and use it in GitHub Desktop.
let debounce, debounceQueue;
debounceQueue = {};
debounce = function(fn, id, delay, args, that) {
delay = delay || 1000;
that = that || this;
args = args || new Array();
if (typeof debounceQueue[id] !== "object") {
debounceQueue[id] = new Object();
}
if (typeof debounceQueue[id].debounceTimer !== "undefined") {
clearTimeout(debounceQueue[id].debounceTimer);
}
return debounceQueue[id] = {
fn: fn,
id: id,
delay: delay,
args: args,
debounceTimer: setTimeout(function() {
debounceQueue[id].fn.apply(that, debounceQueue[id].args);
return debounceQueue[id] = void 0;
}, delay)
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment