You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
388 B

1 month ago
  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