Skip to content

Instantly share code, notes, and snippets.

@lozandier
Created January 9, 2020 22:26
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 lozandier/25eb2253c6594bbd5ce8436454d5db1c to your computer and use it in GitHub Desktop.
Save lozandier/25eb2253c6594bbd5ce8436454d5db1c 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: 'vendingMachine',
initial: 'idle',
context: {
deposited: 0,
},
states: {
idle: {
on: {
SELECT_ITEM: {
target: 'vending',
cond: 'depositedEnough',
},
DEPOSIT_QUARTER: {
actions: ['addQuarter'],
},
},
},
vending: {},
},
},
{
actions: {
addQuarter: assign({
deposited: context => context.deposited + 25,
}),
},
guards: {
depositedEnough: context => context.deposited >= 100,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment