Skip to content

Instantly share code, notes, and snippets.

@mr-mig
Created November 22, 2019 12:28
Show Gist options
  • Save mr-mig/f7f869c72b361b3e8e1d34eb011df18c to your computer and use it in GitHub Desktop.
Save mr-mig/f7f869c72b361b3e8e1d34eb011df18c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const realtime = Machine(
{
id: 'realtime',
initial: 'init',
context: {
periodicSyncInterval: 120 * 1000,
realtimeRetryInterval: 25 * 1000,
},
states: {
init: {
on: {
'': 'connecting'
}
},
connecting: {
invoke: {
src: 'startLongpolling',
onDone: 'connected',
onError: 'disconnected'
}
},
connected: {
invoke: {
src: 'realtimeDataParser'
},
on: {
REALTIME_NETWORK_ERROR: 'disconnected',
REALTIME_DISCONNECT: 'disconnected'
}
},
disconnected: {
after: {
REALTIME_RETRY_INTERVAL: 'connecting'
}
}
}
},
{
delays: {
REALTIME_RETRY_INTERVAL: ctx => ctx.realtimeRetryInterval
},
services: {
startLongpolling: ctx => Promise.resolve(),
realtimeDataParser: ctx => callback => {
// TODO: get XHR from ctx
// callback('REALTIME_TIEMOUT'),
// callback('REALTIME_DISCONNECT')
// callback('REALTIME_PARSED_DATA')
},
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment