Skip to content

setNodes Batching

Add many nodes as one change rather than many: AddNodes takes the whole batch in one call, and EditAsync folds any number of calls into one edit. Either way the canvas raises NodesChanged once and records one undo step for the lot, which the counters here make visible.

0 nodes · NodesChanged raised 0 times · 0 undo steps
Arrow keys move the view, Home shows the whole flow.
bit Blow

Try it

  • Pick how many Nodes to add, then press Add in one call: the nodes appear together, NodesChanged goes up by one and there is one more undo step.
  • Press Add one by one: the same nodes, but the counter and the undo steps go up by one per node, and Undo takes back only the last one.
  • Press Add in one edit: the same calls one at a time again, wrapped in one edit - one event, one step, and Undo takes the whole batch back.
  • Add 500 a few times, then scroll to zoom in and drag the background to pan: only the nodes in view are drawn, while the minimap shows them all.
  • Clear removes everything in one undoable step.

How it works

  • AddNodes(params BlowNode[] nodes) appends the whole array to Nodes and treats it as one edit: one NodesChanged, one OnGraphChanged, one undo step labelled add, and one measuring pass for the lot after the next render.
  • Called once per node, each call is an edit of its own - an event and an undo step each - though Blazor still renders the canvas once, after the handler.
  • EditAsync(action, label) runs the action as a single edit: any number of AddNodes calls, or direct changes to the lists, inside it raise NodesChanged once at the end, are recorded as one undo step under the label you give (add batch here), and render once.
  • HistoryEnabled keeps the undo stack, here with a HistoryCapacity of 1,000 so that adding 500 one by one does not push the earlier steps out; OnHistoryChanged reports the depth and the label of the step UndoAsync() would take back.
  • OnlyRenderVisibleElements draws only the nodes and edges inside the view, which keeps a pan over hundreds of nodes smooth. The nodes have an explicit Width and Height, so their size is known before they are first drawn.
  • Clear empties both lists inside EditAsync(..., label: "clear"), so the canvas records it; changed directly in a handler of the page, the lists would be redrawn but the history would not know.
An unhandled error has occurred. Reload 🗙