Skip to content

Instantly share code, notes, and snippets.

@christiannwamba
Created May 14, 2020 17:49
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 christiannwamba/893f1b0b7a942f4816384daac4d520c9 to your computer and use it in GitHub Desktop.
Save christiannwamba/893f1b0b7a942f4816384daac4d520c9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// DEMO: Guarding
const vendingMachineMachine = 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