throttle.js 586 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. module.exports = function (t, a, d) {
  3. var called = 0;
  4. var fn = t(function () {
  5. ++called;
  6. }, 200);
  7. fn();
  8. a(called, 1);
  9. fn();
  10. fn();
  11. a(called, 1);
  12. // Wait 120ms
  13. setTimeout(function () {
  14. a(called, 1);
  15. fn();
  16. // Wait 120ms
  17. setTimeout(function () {
  18. a(called, 2);
  19. fn();
  20. fn();
  21. // Wait 80ms
  22. setTimeout(function () {
  23. a(called, 2);
  24. // Wait 120ms
  25. setTimeout(function () {
  26. a(called, 3);
  27. // Wait 400ms
  28. setTimeout(function () {
  29. a(called, 3);
  30. d();
  31. }, 400);
  32. }, 120);
  33. }, 80);
  34. }, 120);
  35. }, 120);
  36. };