Last active
June 30, 2023 17:02
-
-
Save Hochul822/7f3b664cd061846404fa276fb30f8324 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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