Skip to content

Instantly share code, notes, and snippets.

@Hochul822
Last active June 30, 2023 17:02
Show Gist options
  • Save Hochul822/7f3b664cd061846404fa276fb30f8324 to your computer and use it in GitHub Desktop.
Save Hochul822/7f3b664cd061846404fa276fb30f8324 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const vendingMachine = Machine(
{
id: "vendingMachine",
initial: "idle",
context: {
deposited: 0,
},
states: {
idle: {
on: {
SELECT_ITEM: {
target: "vending",
cond: "depositedEnough",
},
DEPOSIT_QUATER: {
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