Created
November 22, 2019 12:28
-
-
Save mr-mig/f7f869c72b361b3e8e1d34eb011df18c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
// 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