Skip to content

Instantly share code, notes, and snippets.

@larrybotha
Last active September 20, 2019 21:14
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 larrybotha/e2c705ec261d849fea7b231e96b0c92e to your computer and use it in GitHub Desktop.
Save larrybotha/e2c705ec261d849fea7b231e96b0c92e to your computer and use it in GitHub Desktop.
LunaMed UI User Machine: https://xstate.js.org/viz
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