4 * Returns a function, that, as long as it continues to be invoked, will not
5 * be triggered. The function will be called after it stops being called for
6 * N milliseconds. If `immediate` is passed, trigger the function on the
7 * leading edge, instead of the trailing.
8 * @attribution https://davidwalsh.name/javascript-debounce-function
14 export function debounce(func, wait, immediate) {
17 const context = this, args = arguments;
18 const later = function() {
20 if (!immediate) func.apply(context, args);
22 const callNow = immediate && !timeout;
23 clearTimeout(timeout);
24 timeout = setTimeout(later, wait);
25 if (callNow) func.apply(context, args);