Skip to content

The agent that grows with you

refactor(desktop): rafCoalesce cancel/finish share one frame teardown

kshitijk4poor9f07393b85ca
diff --git a/apps/desktop/src/lib/raf-coalesce.ts b/apps/desktop/src/lib/raf-coalesce.ts
index 0f581f44a73..a7bc09453e3 100644
--- a/apps/desktop/src/lib/raf-coalesce.ts
+++ b/apps/desktop/src/lib/raf-coalesce.ts
@@ -20,20 +20,20 @@ export function rafCoalesce<T>(apply: (value: T) => void): {
}
}
+ const dropFrame = (): void => {
+ if (frame !== null) {
+ cancelAnimationFrame(frame)
+ frame = null
+ }
+ }
+
return {
cancel() {
- if (frame !== null) {
- cancelAnimationFrame(frame)
- frame = null
- }
-
+ dropFrame()
pending = null
},
finish() {
- if (frame !== null) {
- cancelAnimationFrame(frame)
- frame = null
- }
+ dropFrame()
if (pending !== null) {
apply(pending)