debounce.js 761 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. Drupal.debounce = function (func, wait, immediate) {
  8. var timeout = void 0;
  9. var result = void 0;
  10. return function () {
  11. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  12. args[_key] = arguments[_key];
  13. }
  14. var context = this;
  15. var later = function later() {
  16. timeout = null;
  17. if (!immediate) {
  18. result = func.apply(context, args);
  19. }
  20. };
  21. var callNow = immediate && !timeout;
  22. clearTimeout(timeout);
  23. timeout = setTimeout(later, wait);
  24. if (callNow) {
  25. result = func.apply(context, args);
  26. }
  27. return result;
  28. };
  29. };