Skip to content

Instantly share code, notes, and snippets.

@ChrisShank
Created April 25, 2021 06:43
Show Gist options
  • Save ChrisShank/8fcc3c610d54d28ede0b46890aa53df5 to your computer and use it in GitHub Desktop.
Save ChrisShank/8fcc3c610d54d28ede0b46890aa53df5 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const clientMachine = Machine(
{
id: 'client',
initial: 'idle',
context: {
error: null,
response: null,
},
states: {
idle: {
on: {
START: 'connecting',
},
},
connecting: {
invoke: {
src: 'connectToHost',
// Not sure if connecting to the host returns anything, if it does then add an assign action below
onDone: { target: 'connected' },
onError: { target: '#client.faulted', actions: 'assignError' },
},
},
connected: {
initial: 'idle',
// Not sure what is being modeled here
states: {
idle: {},
},
on: {
FAULT: { target: '#client.faulted', actions: 'assignError'}
}
},
faulted: {
type: 'final',
entry: (context, event) => console.log(context.error),
},
},
},
{
actions: {
assignResponse: assign({
response: (context, event) => event.data,
}),
assignError: assign({
error: (context, event) => event.data,
}),
},
services: {
async connectToHost(context, event) {
return true;
},
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment