Skip to content

Instantly share code, notes, and snippets.

@davidkpiano
Created May 28, 2021 21:54
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 davidkpiano/6f46cc8f14e560a8e9fea2c21a9f3b86 to your computer and use it in GitHub Desktop.
Save davidkpiano/6f46cc8f14e560a8e9fea2c21a9f3b86 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine({
id: 'ATM',
initial: 'idle',
states: {
idle: {
on: {
INSERT_CARD: 'authenticating',
}
},
authenticating: {
on: {
CANCEL: 'ejectingCard',
ERROR: 'ejectingCard'
},
initial: 'readingCard',
states: {
readingCard: {
on: {
ACCEPT_CARD: 'askingForPIN',
REJECT_CARD: {
actions: raise('ERROR')
},
}
},
askingForPIN: {
on: {
ENTER_PIN: 'checkingPIN'
}
},
checkingPIN: {
on: {
ACCEPT_PIN: '#ATM.banking',
REJECT_PIN: 'askingForPIN',
}
},
},
},
banking: {
on: {
CANCEL: 'ejectingCard',
},
initial: 'choosingTransaction',
states: {
choosingTransaction: {
on: {
CONFIRM_TRANSACTION: 'performingTransaction',
}
},
performingTransaction: {
after: {
2000: 'choosingTransaction',
}
},
},
},
ejectingCard: {
after: {
2000: '#ATM.idle',
}
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment