Skip to content

Instantly share code, notes, and snippets.

@kad3nce
Created February 22, 2021 23:58
Show Gist options
  • Save kad3nce/495a1630d66fc364b6ab2c7a9b5c1fc9 to your computer and use it in GitHub Desktop.
Save kad3nce/495a1630d66fc364b6ab2c7a9b5c1fc9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const networkStatusMachine = Machine({
id: 'networkStatus',
initial: 'uninitialized',
states: {
uninitialized: {
on: {
// NETWORK_REQUEST_SUCCESS: 'online',
// NETWORK_REQUEST_ERROR: 'offline',
WEBSOCKET_MESSAGE_RECEIVED: 'online',
},
},
online: {
id: 'online',
on: {
// NETWORK_REQUEST_ERROR: 'offline',
WEBSOCKET_HEARTBEAT_MISSED: 'offline',
WEBSOCKET_CLOSED: 'offline',
},
},
offline: {
initial: 'WAITING',
states: {
WAITING: {
on: {
'*': { actions: 'buffer_messages_received_during_waiting_period' },
},
after: {
10000: 'ACCEPTING_EVENTS',
},
},
ACCEPTING_EVENTS: {
on: {
// NETWORK_REQUEST_SUCCESS: 'online',
WEBSOCKET_MESSAGE_RECEIVED: '#online',
},
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment