All files / helper generic.js

64.29% Statements 9/14
44.44% Branches 4/9
66.67% Functions 2/3
75% Lines 9/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  2x 3x 3x 2x 2x       2x 2x     2x 2x      
 
export const debounce = function (func, wait, immediate = false) { // eslint-disable-line
  let timeout = false;
  return function (...args) { // eslint-disable-line
    const context = this;
    const later = () => {
      timeout = null;
      if (!immediate) func.apply(context, args);
    };
    const callNow = immediate && !timeout;
    Iif (timeout) {
      clearTimeout(timeout);
    }
    timeout = setTimeout(later, wait);
    Iif (callNow) func.apply(context, args);
  };
};