Created
April 25, 2021 06:43
-
-
Save ChrisShank/8fcc3c610d54d28ede0b46890aa53df5 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
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