throttleByRaf.mjs 412 B

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