Last active
August 12, 2019 13:22
-
-
Save abierbaum/c66d4141645676ef2e8c72c20869179e 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 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