Skip to content
PACKAGES

batch()

Run updates as one coalesced batch.

import { batch } from "@graphrefly/ts/core";
function batch(fn: (bctx: BatchCtx) => R): R
ParameterTypeDescription
fn(bctx: BatchCtx) => RSynchronous callback that performs node updates and may call rollback().

The callback return value when the batch commits.

import { batch } from "@graphrefly/ts/core";
import { graph } from "@graphrefly/ts/graph";
const g = graph();
const left = g.state(0);
const right = g.state(0);
batch(() => {
left.set(1);
right.set(2);
});
  • Coalescing: DATA/RESOLVED/INVALIDATE settle slices are deferred until commit so shared downstream nodes recompute once for the batch.

packages/ts/src/batch/batch.ts