Skip to content

Instantly share code, notes, and snippets.

@renancaraujo
Created October 25, 2018 15:55
Show Gist options
  • Save renancaraujo/f04aa87db58ad545b24eaddcdc5c3ad0 to your computer and use it in GitHub Desktop.
Save renancaraujo/f04aa87db58ad545b24eaddcdc5c3ad0 to your computer and use it in GitHub Desktop.
/** only executes the last callback sent of a unique id**/
const finalTimeout = (function() {
const timers = {};
return function(callback, ms, uniqueId) {
if (!uniqueId) {
uniqueId = 'default';
}
if (timers[uniqueId]) {
window.clearTimeout(timers[uniqueId]);
}
timers[uniqueId] = setTimeout(() => {
delete timers[uniqueId];
callback();
}, ms);
};
})();
@renancaraujo
Copy link
Author

renancaraujo commented Oct 25, 2018

finalTimeout(() =>
{console.log(ooe)
}, 1e3, 'note-saving');

@EnKaizer
Copy link

let bounce = '';
export const debounce = (func, timeout) => {
  bounce && window.clearTimeout(bounce);
  bounce = setTimeout(() => {
    bounce = '';
    func();
  }, timeout);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment