Skip to content

Instantly share code, notes, and snippets.

@leeahoward
Last active October 26, 2022 00:06
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 leeahoward/5054e4edfff5d13bd7befca81aa8336d to your computer and use it in GitHub Desktop.
Save leeahoward/5054e4edfff5d13bd7befca81aa8336d 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: 'fetch',
initial: 'menu',
context: {
retries: 0
},
states: {
menu: {
on: {
registerClick: 'registerSignIn'
}
},
registerSignIn:{
on:{
signInSuccess:'scanLicense'
}
},
scanLicense:{
on:{
validLicense:'itemScanner',
invalidLicense:'warningMessage'
}
},
warningMessage:{
},
itemScanner:{
on:{
itemScan:'addItem',
payClick:'awaitPayment',
cancelTransaction:'scanLicense',
menu:'menu'
}
},
awaitPayment:{
paymentSuccess:'scanLicense',
paymentFailure:'paymentFailed'
},
paymentFailed:{
okClick:'awaitPayment'
},
addItem:{
on:{
RESOLVE:'itemScanner',
REJECT: 'itemScanner'
}
},
loading: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: {
target: 'loading',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment