Creates a debounced render queue using requestAnimationFrame.
This utility ensures that a callback is executed exactly once right before
the next visual frame, regardless of how many times the trigger is called
synchronously. It safely prevents layout thrashing and redundant computations.
Parameters
cb: ()=>void
The function to execute on the next animation frame.
Returns {cancel():void;():void}
A trigger function that schedules the callback. It includes a .cancel() method to abort the pending frame.
*
Example
letrenderQueue = makeRenderQueue(() => { console.log('DOM updated!') }) * // Calling this multiple times synchronously... renderQueue() renderQueue() renderQueue() * // ...will only result in one 'DOM updated!' log on the next frame.
Example
// Canceling a scheduled render (e.g., when a component unmounts) lettrigger = makeRenderQueue(updateLayout) trigger() trigger.cancel() // The callback will not execute
Creates a debounced render queue using
requestAnimationFrame. This utility ensures that a callback is executed exactly once right before the next visual frame, regardless of how many times the trigger is called synchronously. It safely prevents layout thrashing and redundant computations.