throttleByRaf.js 536 B

1234567891011121314151617181920212223
  1. Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  2. const require_raf = require('./raf.js');
  3. //#region ../../packages/utils/throttleByRaf.ts
  4. function throttleByRaf(cb) {
  5. let timer = 0;
  6. const throttle = (...args) => {
  7. if (timer) require_raf.cAF(timer);
  8. timer = require_raf.rAF(() => {
  9. cb(...args);
  10. timer = 0;
  11. });
  12. };
  13. throttle.cancel = () => {
  14. require_raf.cAF(timer);
  15. timer = 0;
  16. };
  17. return throttle;
  18. }
  19. //#endregion
  20. exports.throttleByRaf = throttleByRaf;
  21. //# sourceMappingURL=throttleByRaf.js.map