Skip to content

Instantly share code, notes, and snippets.

@andreabadesso
Created August 4, 2023 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreabadesso/2e30ab7808e337edb78524ade938a5fb to your computer and use it in GitHub Desktop.
Save andreabadesso/2e30ab7808e337edb78524ade938a5fb to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const websocketMachine = Machine({
id: 'websocket',
initial: 'CONNECTING',
context: {
lastEventId: null,
socket: null,
},
invoke: {
src: 'initializeWebSocket',
onDone: 'CONNECTED',
},
states: {
CONNECTING: {
on: {
CONNECTED: {
target: 'CONNECTED.idle',
actions: 'storeSocket',
},
}
},
CONNECTED: {
onEntry: 'startStream',
on: {
DISCONNECT: {
target: 'CONNECTING',
},
},
initial: 'idle',
states: {
idle: {
on: {
NEW_VERTEX_ACCEPTED: {
actions: ['storeEvent'],
target: 'handlingVertexAccepted',
},
VERTEX_METADATA_CHANGED: {
actions: ['storeEvent'],
target: 'handlingMetadataChanged',
},
LOAD_STARTED: {
actions: ['storeEvent'],
target: 'success',
},
REORG_STARTED: {
actions: ['storeEvent'],
target: 'success',
},
REORG_ENDED: {
actions: ['storeEvent'],
target: 'success',
},
ACK: {
actions: 'sendAck'
},
'*': {
actions: ['storeEvent'],
target: 'success',
}
}
},
handlingMetadataChanged: {
invoke: {
src: 'handleMetadataChanged',
data: (_context, event) => event,
onDone: 'success',
onError: 'error',
},
},
handlingVertexAccepted: {
invoke: {
src: 'handleVertexAccepted',
data: (_context, event) => event,
onDone: 'success',
onError: 'error',
},
},
success: {
entry: 'sendAck',
always: [
{ target: 'idle' }
],
},
error: {
type: 'final',
entry: 'logError',
},
}
}
}
}, {
actions: {
},
services: {
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment