Skip to content

@jsvision/ui / batch

Function: batch()

batch<T>(fn): T

Defined in: ui/src/reactive/scheduler.ts:299

Coalesce multiple writes into a single update. Run fn with propagation suspended; dependents re-run just once, after fn returns, observing the final values of every signal written inside. Nested batches join the outer one — only the outermost close triggers the flush.

Type Parameters

T

T

Parameters

fn

() => T

The function whose writes are coalesced.

Returns

T

Whatever fn returns.

Example

ts
import { signal, effect, batch } from '@jsvision/ui';

const first = signal('Ada');
const last = signal('Lovelace');
effect(() => console.log(first(), last()));

batch(() => {
  first.set('Grace');
  last.set('Hopper');
}); // effect re-runs ONCE → "Grace Hopper" (not twice)