Created
October 22, 2019 14:02
-
-
Save larrybotha/41bcf51516e1ff26faa161b1b7daaea3 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
// Luna Med user auth machine | |
const authUserMachine = Machine({ | |
id: 'user', | |
initial: 'noUser', | |
context: { | |
error: undefined, | |
user: undefined, | |
}, | |
states: { | |
noUser: { | |
on: {FETCH: 'fetching'}, | |
}, | |
fetching: { | |
invoke: { | |
id: 'fetchUser', | |
src: 'fetchUser', | |
onDone: { | |
actions: 'handleUserFound', | |
target: 'found', | |
}, | |
onError: [ | |
{ | |
actions: 'handleError', | |
cond: 'userNotFound', | |
target: 'creating', | |
}, | |
{ | |
actions: 'handleError', | |
target: 'error', | |
}, | |
], | |
}, | |
on: {FETCH_CANCEL: 'noUser'}, | |
}, | |
creating: { | |
invoke: { | |
id: 'createUser', | |
src: 'createUser', | |
onDone: { | |
actions: 'handleUserFound', | |
target: 'found', | |
}, | |
onError: { | |
actions: 'handleError', | |
target: 'error', | |
}, | |
}, | |
on: {CREATE_CANCEL: 'noUser'}, | |
}, | |
error: { | |
on: {FETCH: 'fetching'}, | |
}, | |
found: { | |
data: { | |
user: (context) => context.user, | |
}, | |
type: 'final', | |
}, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment