Skip to content

Instantly share code, notes, and snippets.

@tigranpetrossian
Created July 17, 2021 19:52
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 tigranpetrossian/259347c00ab0dbd7400875946a4d2efc to your computer and use it in GitHub Desktop.
Save tigranpetrossian/259347c00ab0dbd7400875946a4d2efc 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: 'session',
initial: 'checkingAuth',
states: {
checkingAuth: {
on: {
REPORT_TOKEN_EXISTS: { target: 'authenticated' },
REPORT_TOKEN_DOESNT_EXIST: { target: 'unauthenticated' },
},
invoke: {
id: 'authCheck',
src: 'checkAuthentication',
},
},
unauthenticated: {
initial: 'idle',
states: {
idle: {},
error: {},
},
on: {
LOG_IN: {
target: 'loggingIn',
},
},
},
loggingIn: {
invoke: {
id: 'login',
src: 'login',
onDone: {
target: 'authenticated',
actions: ['persistToken'],
},
onError: {
target: 'unauthenticated.error',
},
},
},
authenticated: {
initial: 'initializingApp',
states: {
initializingApp: {
on: {
READY: { target: 'active' },
},
},
active: {
on: {
SWITCH_TENANT: { target: 'switchingTenant' },
},
},
switchingTenant: {
on: {
SWITCH_TENANT_SUCCESS: { target: 'active' },
},
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment