Skip to content

Instantly share code, notes, and snippets.

@gabrocheleau
Last active August 31, 2020 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrocheleau/abc070d1a560c1bc1d960d6feeee9ee9 to your computer and use it in GitHub Desktop.
Save gabrocheleau/abc070d1a560c1bc1d960d6feeee9ee9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const ConnectionMachine = Machine({
id: 'connection',
initial: 'inactive',
context: {},
on: {
CONNECT: {
actions: ['assignConnector'],
target: '#active',
},
},
states: {
active: {
id: 'active',
initial: 'connecting',
exit: 'clearConnection',
invoke: {
id: 'connector',
src: {
type: 'connector',
},
onError: {
// Allow connectors to escalate errors back to the parent machine.
actions: ['handleConnectorError'],
target: '#error',
},
onDone: {
// Allow less complex connectors to prepare the connection simply by e.g. resolving a promise.
actions: ['handleConnectorDone'],
target: '#connected',
},
},
on: {
// Allow more complex connectors to manage the connection state by sending events to the parent.
DISCONNECT: '#inactive',
ERROR: {
actions: ['assignError'],
target: '#error',
},
},
states: {
connecting: {
id: 'connecting',
on: {
CONNECTED: {
actions: ['assignConnection'],
target: '#connected',
},
},
},
connected: {
id: 'connected',
on: {
ACCOUNTS_CHANGED: {
actions: ['assignAccounts'],
},
NETWORK_CHANGED: {
actions: ['assignNetwork'],
},
},
},
},
},
inactive: {
id: 'inactive',
initial: 'idle',
states: {
idle: {
id: 'idle',
},
error: {
id: 'error',
exit: 'clearError',
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment