Import AITURK IDE 1.0.0-beta.1 from Hermes 63279301; preserve MIT license
This commit is contained in:
commit
03634b1ca3
11340 files changed
+3442369
No files matched your search
@@ -0,0 +1,34 @@
|
||||
/** Coalesce a stream of values (pointermove positions, resize deltas) to one
|
||||
* `apply` per animation frame, so a drag can't drive several layouts per frame.
|
||||
* `push` records the latest value and schedules a frame; `finish` commits the
|
||||
* last value and cancels any pending frame (call it on pointerup/cancel).
|
||||
* `null` is the empty sentinel, so `T` must never legitimately be `null`. */
|
||||
export function rafCoalesce<T>(apply: (value: T) => void): { finish: () => void; push: (value: T) => void } {
|
||||
let frame: null | number = null
|
||||
let pending: null | T = null
|
||||
|
||||
const flush = () => {
|
||||
frame = null
|
||||
|
||||
if (pending !== null) {
|
||||
apply(pending)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
finish() {
|
||||
if (frame !== null) {
|
||||
cancelAnimationFrame(frame)
|
||||
frame = null
|
||||
}
|
||||
|
||||
if (pending !== null) {
|
||||
apply(pending)
|
||||
}
|
||||
},
|
||||
push(value) {
|
||||
pending = value
|
||||
frame ??= requestAnimationFrame(flush)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user