All files / app/utilities debounce.ts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15        13x 1x     1x 1x 1x        
// https://codeburst.io/throttling-and-debouncing-in-javascript-646d076d0a44
 
export function debounce(fn, delay): (args: any) => any {
  let timerId;
  return function(...args) {
    Iif (timerId) {
      clearTimeout(timerId);
    }
    timerId = setTimeout(() => {
      fn(...args);
      timerId = null;
    }, delay);
  };
}