We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1479a26 commit 02e92d0Copy full SHA for 02e92d0
frontend/src/ts/utils/debounced-animation-frame.ts
@@ -0,0 +1,21 @@
1
+const pendingFrames = new Map<string, number>();
2
+
3
+export function requestDebouncedAnimationFrame(
4
+ frameId: string,
5
+ callback: () => void
6
+): void {
7
+ cancelIfPending(frameId);
8
+ const frame = requestAnimationFrame(() => {
9
+ pendingFrames.delete(frameId);
10
+ callback();
11
+ });
12
+ pendingFrames.set(frameId, frame);
13
+}
14
15
+function cancelIfPending(frameId: string): void {
16
+ const pending = pendingFrames.get(frameId);
17
+ if (pending !== undefined) {
18
+ cancelAnimationFrame(pending);
19
20
+ }
21
0 commit comments