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