You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design/components/_util/throttleByAnimationFrame.ts

26 lines
494 B
TypeScript

import raf from 'rc-util/lib/raf';
function throttleByAnimationFrame<T extends any[]>(fn: (...args: T) => void) {
let requestId: number | null;
const later = (args: T) => () => {
requestId = null;
fn(...args);
};
const throttled = (...args: T) => {
if (requestId == null) {
requestId = raf(later(args));
}
};
throttled.cancel = () => {
raf.cancel(requestId!);
requestId = null;
};
return throttled;
}
export default throttleByAnimationFrame;