Yegoroot
4/18/2018 - 9:06 AM

JS__functionDebounce

JS__functionDebounce

  // From https://davidwalsh.name/javascript-debounce-function.
  const debounce = (func, wait, immediate) => { 
    let timeout;
    return function () {
      let context = this;
      var args = arguments;
      let later = () => {
        timeout = null;
        if (!immediate) func.apply(context, args);
      };
      let callNow = immediate && !timeout;
      clearTimeout(timeout);
      timeout = setTimeout(later, wait);
      if (callNow) func.apply(context, args);
    };
  };