Skip to content

Instantly share code, notes, and snippets.

@SilentEchoGM
Created September 8, 2020 09:01
Show Gist options
  • Save SilentEchoGM/4524c76af7cde66dd966e4be91d8eb6c to your computer and use it in GitHub Desktop.
Save SilentEchoGM/4524c76af7cde66dd966e4be91d8eb6c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const loginMachine = Machine({
id: 'loginMachine',
context: {
tag: '',
token: ''
},
initial: 'tagEntry',
states: {
tagEntry: {
on: {
ENTER_TAG: {
actions: 'cacheTag'
},
SUBMIT: [
{
cond: 'isBadTagFormat',
target: 'tagError.badFormat'
},
{
target: 'awaitingResponseTag'
}
]
}
},
awaitingResponseTag: {
invoke: {
src: 'requestSignInTag',
onDone: {
target: 'tokenEntry'
},
onError: [
{
cond: 'isTagNotFound',
target: 'tagError.notFound'
},
{
cond: 'isServiceError',
target: 'serviceError'
}
]
}
},
tagError: {
on: {
ENTER_TAG: {
actions: 'cacheTag',
target: 'tagEntry'
}
},
initial: 'badFormat',
states: {
badFormat: {},
notFound: {}
}
},
tokenEntry: {
on: {
ENTER_TOKEN: {
actions: 'cacheToken'
},
SUBMIT: [
{
cond: 'isBadTokenFormat',
target: 'tokenError.badFormat'
},
{
target: 'awaitingResponseToken'
}
]
}
},
awaitingResponseToken: {
invoke: {
src: 'requestSignInToken',
onDone: {
target: 'loggedIn'
},
onError: [
{
cond: 'isTokenIncorrect',
target: 'tokenError.incorrect'
},
{
cond: 'isServiceError',
target: 'serviceError'
}
]
}
},
tokenError: {
on: {
ENTER_TOKEN: {
actions: 'cacheToken',
target: 'tokenEntry'
}
},
initial: 'badFormat',
states: {
badFormat: {},
incorrect: {}
}
},
serviceError: {
on: {
SUBMIT: {
target: 'tagEntry'
}
}
},
loggedIn: {
type: 'final'
},
onDone: {
actions: 'onAuthentication'
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment