-
StateNode Structure
- initial: Points to the initial child
StateNode - transitions: Includes
eventType,cond | condition | guard,actions, and a shortdescription - id, key: Identifiers for the node
string - states: An array of children
StateNode[] - order: A numeric indicator (e.g. 1, 2, 3), likely matching the definition order
- description: A brief explanation of the node’s role optional
string - definition: References to
invoke,entry, andexitactionsRecord<'name' | 'id', string> - tags: State tags
string[] - parent:
StateNode - type: Either
atomicorcompound(only the root node iscompoundin Zag) => The machine is a node (root node)
- initial: Points to the initial child
-
Building the Tree
- Create a root
StateNodeand attach each state as a child (statesarray). - Since Zag doesn’t use nested states, this is just one level below root.
- Traverse all nodes to set their
parentand assign anorderif needed.
- Create a root
-
Creating a Directed Graph
- Once the
Rootnode and its children are established, construct a directed graph from them. - Each
StateNodebecomes a node, and each transition becomes a directed edge.
- Once the
-
Simulation
- The plan is to run the machine, send events, and check which
StateNodeis active and what the context is. - Guards (
cond) can be asked dynamically, context can change, and transitions determine the new active state.
- The plan is to run the machine, send events, and check which
-
Visualization
- We use elkjs for graph
- Support panning, autolayout
-
Data
- We wanna be able to parse machine code. i.e. evaluating machine schema in isolated browser environment. This result can then be interpreted by
useMachine - https://github.com/maple3142/wasm-jseval
- We wanna be able to parse machine code. i.e. evaluating machine schema in isolated browser environment. This result can then be interpreted by
Notes
- Sending events to child machines in Zag => Set, Send, Register, Use
- Visualizer only expects a machine, so parsing happens outside
- Getting intial state from running machine.
service.state.initial
Miscellanous - (Possible Future)
- Embeds
- Syncing with a visual component
Resolve
- Getting next events of active state