debounce.ts 351 B

123456789101112131415
  1. /* eslint-disable */
  2. const debounce = (fn: Function, delay: number) => {
  3. let timer: NodeJS.Timeout | null = null;
  4. return function () {
  5. // @ts-ignore
  6. const context = this;
  7. const args = arguments;
  8. if (timer) {
  9. clearTimeout(timer);
  10. }
  11. timer = setTimeout(fn.apply(context, args), delay);
  12. };
  13. };
  14. export default debounce;