debounce.esm.js 989 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * @link https://davidwalsh.name/javascript-debounce-function
  3. * @param func needs to implement a function which is debounced
  4. * @param wait how long do you want to wait till the previous declared function is executed
  5. * @param isImmediate defines if you want to execute the function on the first execution or the last execution inside the time window. `true` for first and `false` for last.
  6. */
  7. var debounce = ((func, wait, isImmediate) => {
  8. let timeout;
  9. return function debounce(...args) {
  10. const context = this;
  11. const later = () => {
  12. timeout = undefined;
  13. if (!isImmediate) {
  14. func.apply(context, args);
  15. }
  16. };
  17. const shouldCallNow = isImmediate && !timeout;
  18. if (timeout !== undefined) {
  19. clearTimeout(timeout);
  20. }
  21. timeout = setTimeout(later, wait);
  22. if (shouldCallNow) {
  23. return func.apply(context, args);
  24. }
  25. return undefined;
  26. };
  27. });
  28. export { debounce as default };
  29. //# sourceMappingURL=debounce.esm.js.map