throttle.js 580 B

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