export default function debounce()

in src/utils/debounce.js [19:49]


export default function debounce(fn, delay, atStart, guarantee) {
  let timeout;
  let self;

  return function debounced(...args) {
    self = this;

    function clear() {
      clearTimeout(timeout);
      timeout = null;
    }

    function run() {
      clear();
      fn.apply(self, args);
    }

    if (timeout && (atStart || guarantee)) {
      return;
    }
    if (!atStart) {
      clear();

      timeout = setTimeout(run, delay);
      return;
    }

    timeout = setTimeout(clear, delay);
    fn.apply(self, args);
  };
}