throttleByRaf.js 484 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var raf = require('./raf.js');
  4. function throttleByRaf(cb) {
  5. let timer = 0;
  6. const throttle = (...args) => {
  7. if (timer) {
  8. raf.cAF(timer);
  9. }
  10. timer = raf.rAF(() => {
  11. cb(...args);
  12. timer = 0;
  13. });
  14. };
  15. throttle.cancel = () => {
  16. raf.cAF(timer);
  17. timer = 0;
  18. };
  19. return throttle;
  20. }
  21. exports.throttleByRaf = throttleByRaf;
  22. //# sourceMappingURL=throttleByRaf.js.map