Skip to content

Instantly share code, notes, and snippets.

@akshaypilankar
Last active September 14, 2021 04:07
Show Gist options
  • Save akshaypilankar/1e567cff699c55a1ce366eec721b5cd9 to your computer and use it in GitHub Desktop.
Save akshaypilankar/1e567cff699c55a1ce366eec721b5cd9 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: 'app',
initial: 'init',
context: {
user:{},
isLoggedIn:false
},
states: {
init:{
on: [ {
cond: 'isLoggedIn',
target: 'profile'
},
{
cond: '!isLoggedIn',
target: 'auth'
}
]},
auth:{
initial: 'login',
states:{
login: {
on: {
ENTER_EMAIL: {
actions: 'cacheEmail'
},
ENTER_PASSWORD: {
actions: 'cachePassword'
},
SUBMIT: [
{
cond: 'isLoggedIn',
target: '#app.profile'
}
],
SIGNUP:'signup',
}
},
signup:{
on: {
ENTER_FULL_NAME: {
actions: 'cacheFullName'
},
ENTER_EMAIL: {
actions: 'cacheEmail'
},
ENTER_PASSWORD: {
actions: 'cachePassword'
},
REENTER_PASSWORD: {
actions: 'cacheReenterPassword'
},
SUBMIT: [
{
cond: 'isLoggedIn',
target: '#app.profile'
}
],
LOGIN:'login'
}
},
}
},
profile: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment