Skip to content

Instantly share code, notes, and snippets.

@hitrik
Last active April 25, 2021 21:30
Show Gist options
  • Save hitrik/d129273655ea718a7856df9523901be2 to your computer and use it in GitHub Desktop.
Save hitrik/d129273655ea718a7856df9523901be2 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const startUserAuth = () => new Promise(res => setTimeout(res('qazzaq'), 1000))
const userMachine = Machine({
id: 'user',
context: {
user: null,
error: false
},
initial: 'idle',
states: {
authorize: {
on: {
'LOGOUT': 'idle'
}
},
loading: {
invoke: {
id: 'userAuth',
src: () => startUserAuth(),
onDone: {
target: 'success',
actions: assign({
user: (_, event) => event.data
})
},
onError: {
target: 'failure',
actions: assign({
error: (_, event) => event.data
})
}
}
},
success: {
type: 'final'
},
failure: {
},
idle: {
on: {
'AUTH': 'loading'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment