Created
June 5, 2021 11:20
-
-
Save jinnkhan88/dbfa56ff4ec095618c10da7a819e24c6 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' | |
}, | |
DESPOSIT_QUATERS:{ | |
actions:['addQuaters'] | |
} | |
} | |
}, | |
vending:{} | |
} | |
},{ | |
actions:{ | |
addQuaters:assign({ | |
deposited:context => context.deposited + 25 | |
}) | |
}, | |
guards:{ | |
depositedEnough:(context,event) => | |
{ | |
return context.deposited >= 100 | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment