protocol.ts is used to specify the configuration of a machine, which describes how a machine operates, and what it does. Each protocol should export the following objects:
config: the machine's configurationmockOptions: (optional) mock options used by the xstate visualizerInit: A type indicating the initial context required by the machinemachine: (store: IStore, context?: Init) => StateMachine<Init, any, any>- Most of the behaviour of machines depend in some way on a data store.
src/store.tscontainsIstore, a "rough draft" of the interface of a store. Themachinefactory hooks the protocol up to an implementationstoreofIStore. It also configures invoked services (child machines)
- Most of the behaviour of machines depend in some way on a data store.
Guards,Actions,Services,Options: (optional) types indicating what options are required.
After updating protocol.ts, run yarn generateConfigs to update protocol.config.js.
Configs (protocol.config.json) are used to generate the visualizations using https://xstate.js.org/viz/.
There is currently no way to automatically generate the visualization from the config.js file (this is apparently in the works for the new year).
The best so far is to copy/paste protocol.config.js into @xstate/viz, and screenshot the visualization.
runtime.ts creates two wallets connected to the message service. The first wallet is sent a CREATE_CHANNEL event.
This should trigger a JoinChannel protocol in the second protocol.