Skip to content

Instantly share code, notes, and snippets.

@guilherme-teodoro
Created November 12, 2020 22:08
Show Gist options
  • Save guilherme-teodoro/381c7516d83ce4d0b6bdf5584d58ccc9 to your computer and use it in GitHub Desktop.
Save guilherme-teodoro/381c7516d83ce4d0b6bdf5584d58ccc9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const toggleMachine = Machine({
id: 'vivo-controle',
initial: 'identification',
states: {
identification: {
meta: {
step: {
number: 1
},
path: '/sp/identification'
},
on: {
NEXT: 'address'
}
},
address: {
entry: ['checkUser'],
meta: {
step: {
number: 2
},
path: '/sp/address'
},
on: {
PREV: 'identification',
INITIAL: 'identification',
NEXT: [
{ target: 'payment', cond: 'isEligible' },
{ target: 'unavailable' },
]
}
},
unavailable: {
meta: { path: '/sp/unavailable' },
type: 'final'
},
payment: {
entry: ['checkUser'],
meta: {
step: {
number: 3
},
path: '/sp/payment'
},
on: {
NEXT: 'token',
INITIAL: 'identification',
PREV: 'address'
}
},
token: {
meta: {
step: {
number: 4
},
path: '/sp/token'
},
on: {
NEXT: 'obrigado',
INITIAL: 'identification',
PREV: 'payment'
}
},
obrigado: {
entry: ['checkUser'],
meta: {
step: {
number: 5
},
path: '/sp/obrigado'
},
on: {
INITIAL: 'identification'
},
type: 'final'
}
}
}, {
guards: {
isEligible: (context, event) => {
return true // mock
}
},
actions: {
checkUser: (context, event) => {
const send = event.service?.send
const { user: { user } } = store.getState()
if (!user) {
send('INITIAL')
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment