Last active
September 20, 2019 21:14
-
-
Save larrybotha/e2c705ec261d849fea7b231e96b0c92e to your computer and use it in GitHub Desktop.
LunaMed UI User Machine: 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 userMachine = Machine({ | |
id: "user", | |
initial: "noUser", | |
states: { | |
noUser: { | |
invoke: { | |
src: "getUser", | |
onDone: "userFound", | |
onError: [ | |
{ | |
cond: "userNotFound", | |
target: "creatingUser", | |
}, | |
{target: "error"}, | |
] | |
}, | |
}, | |
userFound: { | |
type: "final", | |
}, | |
creatingUser: { | |
invoke: { | |
src: "createUser", | |
onDone: "userFound", | |
onError: { | |
target: "error", | |
} | |
} | |
}, | |
error: { | |
on: { | |
RETRY: { | |
target: "noUser", | |
} | |
} | |
}, | |
}, | |
}, { | |
guards: { | |
userNotFound: () => Math.random() > .5, | |
} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment