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.
23 lines
388 B
23 lines
388 B
3 months ago
|
import { cAF, rAF } from './raf.mjs';
|
||
|
|
||
|
function throttleByRaf(cb) {
|
||
|
let timer = 0;
|
||
|
const throttle = (...args) => {
|
||
|
if (timer) {
|
||
|
cAF(timer);
|
||
|
}
|
||
|
timer = rAF(() => {
|
||
|
cb(...args);
|
||
|
timer = 0;
|
||
|
});
|
||
|
};
|
||
|
throttle.cancel = () => {
|
||
|
cAF(timer);
|
||
|
timer = 0;
|
||
|
};
|
||
|
return throttle;
|
||
|
}
|
||
|
|
||
|
export { throttleByRaf };
|
||
|
//# sourceMappingURL=throttleByRaf.mjs.map
|