throttleByRaf.mjs 388 B

12345678910111213141516171819202122
  1. import { cAF, rAF } from './raf.mjs';
  2. function throttleByRaf(cb) {
  3. let timer = 0;
  4. const throttle = (...args) => {
  5. if (timer) {
  6. cAF(timer);
  7. }
  8. timer = rAF(() => {
  9. cb(...args);
  10. timer = 0;
  11. });
  12. };
  13. throttle.cancel = () => {
  14. cAF(timer);
  15. timer = 0;
  16. };
  17. return throttle;
  18. }
  19. export { throttleByRaf };
  20. //# sourceMappingURL=throttleByRaf.mjs.map