Last active
August 31, 2020 13:15
-
-
Save gabrocheleau/abc070d1a560c1bc1d960d6feeee9ee9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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