Skip to content

Instantly share code, notes, and snippets.

@ivandotv
Created July 17, 2021 13:20
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 ivandotv/5fa69810979f7ec0a21e9b9487b6300d to your computer and use it in GitHub Desktop.
Save ivandotv/5fa69810979f7ec0a21e9b9487b6300d 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: 'auth',
// context: authModel.initialContext,
context:{},
initial: 'checking',
states: {
checking: {
invoke: {
src: 'checkAuth',
onDone: [
{
cond: 'hasData',
target: 'signed_in',
actions: 'setAuth'
},
{
target: 'signed_out'
}
],
onError: {
target: 'error',
actions: 'setError'
}
}
},
signed_in: {
on: {
logOut: 'signing_out'
}
},
signing_out: {
invoke: {
src: 'logout',
onDone: {
target: 'signed_out',
actions: ['clearAuth', 'setsigned_outTime']
},
onError: {
target: 'error',
actions: 'setError'
}
}
},
signed_out: {
on: {
signIn: 'signing_in'
}
},
signing_in: {
invoke: {
src: 'signIn',
onDone: {
target: 'signed_in',
cond: 'hasData',
actions: 'setAuth'
},
onError: {
target: 'error',
actions: 'setError'
}
}
},
error: {
on: {
retry: {
target: 'checking',
actions: 'resetContext'
// actions: authModel.assign({
// user: null,
// error: null
// })
}
}
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment