Skip to content

Instantly share code, notes, and snippets.

@abierbaum
Last active August 12, 2019 13:22
Show Gist options
  • Save abierbaum/c66d4141645676ef2e8c72c20869179e to your computer and use it in GitHub Desktop.
Save abierbaum/c66d4141645676ef2e8c72c20869179e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine(
{
id: 'ws_machine',
initial: 'disconnected',
strict: true,
context: {
retries: 0,
},
states: {
disconnected: {
on: {
CONNECT: 'connecting',
},
},
connecting: {
invoke: {
src: 'connect',
onError: {
target: 'disconnected',
actions: 'incRetry',
},
onDone: {
target: 'connected',
actions: 'clearRetry',
},
},
on: {
CONNECT: undefined,
DISCONNECT: 'disconnecting',
},
},
connected: {
initial: 'waiting',
states: {
waiting: {
after: {
HEARTBEAT_TIMEOUT: {target: '#disconnecting'},
},
on: {
// reset the waiting count back
RESET_TIMER: {
internal: false,
target: 'waiting',
},
},
},
},
on: {
DISCONNECT: '#disconnecting',
},
},
disconnecting: {
id: 'disconnecting',
entry: 'disconnect',
on: {
'': 'disconnected',
},
},
},
},
{
delays: {
HEARTBEAT_TIMEOUT: 10000
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment