mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-08 01:53:34 +08:00
fix: set requestId to null after fn was cancelled (#34858)
This commit is contained in:
parent
27bb1ea4ae
commit
c4ffbff841
@ -1,20 +1,26 @@
|
||||
import raf from 'rc-util/lib/raf';
|
||||
|
||||
export function throttleByAnimationFrame(fn: (...args: any[]) => void) {
|
||||
export function throttleByAnimationFrame<T extends unknown[]>(fn: (...args: T) => void) {
|
||||
let requestId: number | null;
|
||||
|
||||
const later = (args: any[]) => () => {
|
||||
const later = (args: T) => () => {
|
||||
requestId = null;
|
||||
fn(...args);
|
||||
};
|
||||
|
||||
const throttled = (...args: any[]) => {
|
||||
const throttled: {
|
||||
(...args: T): void;
|
||||
cancel: () => void;
|
||||
} = (...args: T) => {
|
||||
if (requestId == null) {
|
||||
requestId = raf(later(args));
|
||||
}
|
||||
};
|
||||
|
||||
(throttled as any).cancel = () => raf.cancel(requestId!);
|
||||
throttled.cancel = () => {
|
||||
raf.cancel(requestId!);
|
||||
requestId = null;
|
||||
};
|
||||
|
||||
return throttled;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user