Skip to content

Instantly share code, notes, and snippets.

@itelo
Created April 11, 2020 23:43
Show Gist options
  • Select an option

  • Save itelo/48295f1fa601919c062d9a034a4840ff to your computer and use it in GitHub Desktop.

Select an option

Save itelo/48295f1fa601919c062d9a034a4840ff 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 fetchMachine = Machine({
id: 'authentication',
initial: 'unauthorized',
context: {
user: null,
error: null,
},
states: {
unauthorized: {
on: {
LOGIN: 'loading',
},
},
loading: {
on: {
LOGIN_SUCCESS: {
target: 'authorized',
actions: ['onSuccess'],
},
LOGIN_ERROR: {
target: 'unauthorized',
actions: ['onError'],
},
},
},
authorized: {
on: {
LOGOUT: {
target: 'unauthorized',
actions: ['onLogout'],
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment