batch()
Run updates as one coalesced batch.
Import
Section titled “Import”import { batch } from "@graphrefly/ts/core";Signature
Section titled “Signature”function batch(fn: (bctx: BatchCtx) => R): RParameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
fn | (bctx: BatchCtx) => R | Synchronous callback that performs node updates and may call rollback(). |
Returns
Section titled “Returns”The callback return value when the batch commits.
Example
Section titled “Example”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);});Remarks
Section titled “Remarks”- Coalescing: DATA/RESOLVED/INVALIDATE settle slices are deferred until commit so shared downstream nodes recompute once for the batch.
Source
Section titled “Source”packages/ts/src/batch/batch.ts