Skip to main content

batch_updates

Function batch_updates 

Source
pub fn batch_updates<F, R>(callback: F) -> R
where F: FnOnce() -> R,
Expand description

Batches signal updates within a closure, deferring DOM synchronization until completion.

Saves the current SUPPRESS_SCHEDULE flag, sets it to true, executes the closure, and restores the previous flag value. This prevents schedule_signal_update from queuing microtasks during the closure execution, allowing multiple signal mutations to be applied before triggering a single DOM update cycle.

When the outermost batch_updates call completes (i.e., the previous suppress flag was false), a single schedule_signal_update() is invoked to ensure that any signal mutations performed inside the closure are reflected in the DOM. This is critical for watch! initialisation, where Console::log calls mutate the console signal inside the batched block and must still trigger DynamicNode re-renders.

§Arguments

  • FnOnce() -> R - The closure to execute with batched updates.

§Returns

  • R - The result of the closure execution.