Skip to content

Instantly share code, notes, and snippets.

@simlrh
Created March 4, 2020 16:33
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 simlrh/ad15b10c428cff2a0d3c5cbdb9b78709 to your computer and use it in GitHub Desktop.
Save simlrh/ad15b10c428cff2a0d3c5cbdb9b78709 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const machine = Machine({
id: 'auth',
initial: 'loading',
context: {
email: undefined,
},
states: {
loading: {
// TODO: Check auth state and redirect
after: {
1000: 'loggedOut',
},
},
loggedOut: {
on: {
START_LOGIN: {
target: 'enterEmail',
actions: 'navigateEnterEmail',
},
BACK: undefined,
},
},
enterEmail: {
on: {
SET_EMAIL: {
target: 'enterPassword',
actions: ['setEmail', 'navigateEnterPassword'],
},
BACK: 'loggedOut',
},
},
enterPassword: {
entry: assign({
password: {
attempting: false,
errors: undefined,
},
}),
initial: 'idle',
states: {
idle: {
on: { SET_PASSWORD: 'attempting' },
},
attempting: {
entry: assign({
password: {
attempting: true,
errors: undefined,
},
}),
invoke: {
id: 'login',
src: 'login',
onDone: 'success',
onError: {
target: 'idle',
actions: 'setLoginError',
},
},
},
success: {
type: 'final',
entry: assign({
password: {
attempting: false,
errors: undefined,
},
}),
},
},
on: {
BACK: 'enterEmail',
},
onDone: {
target: 'loggedIn',
actions: 'navigateLoggedIn',
},
},
loggedIn: {
on: {
LOG_OUT: {
target: 'loggedOut',
actions: 'navigateLoggedOut',
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment