Skip to content

External Store

The graph lives in a store object outside any component, the Redux or Zustand pattern: the toolbar dispatches actions to it, the canvas draws its lists, and every change - from an action or from an edit on the canvas - goes through the store, which tells its subscribers to re-render.

store: 1 nodes, 0 edges
Store root
bit Blow

Try it

  • Add node dispatches AddNode: the store appends a node, the canvas draws it and the view glides out to include it.
  • Connect random dispatches ConnectRandom, which joins two nodes that are not yet joined - or logs that every pair already is.
  • Reset replaces the store's state with a single root node.
  • Edit on the canvas - drag a node, drag from a handle to connect two, select something and press Delete - and each edit arrives in the log as a CanvasEdited action with what kind of edit it was, while the readout follows.

How it works

  • FlowStore is a plain class holding the Nodes and Edges lists, a Dispatch(action) method that changes them, and a Changed event raised after every action. The page subscribes in OnInitialized and unsubscribes in Dispose; any number of components could do the same.
  • The canvas is handed the store's lists as Nodes and Edges. Reset hands it new list instances; the canvas reads whatever lists it is given on its next render, so a store that replaces its state rather than mutating it works as well.
  • A user edit changes the lists directly - the canvas always edits the lists it was given in place. OnGraphChanged is raised once per completed edit with a BlowGraphChange, and the page turns it into a CanvasEdited action carrying the change's Label (move, connect, delete, ...), so the store and its subscribers hear of every edit in one place.
  • Add node calls FitViewAsync(300) on the canvas after dispatching, since a new node may land outside the view the graph was fitted to.
An unhandled error has occurred. Reload 🗙