Skip to content

Instantly share code, notes, and snippets.

@jinnkhan88
Created June 5, 2021 11:20
Show Gist options
  • Save jinnkhan88/dbfa56ff4ec095618c10da7a819e24c6 to your computer and use it in GitHub Desktop.
Save jinnkhan88/dbfa56ff4ec095618c10da7a819e24c6 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'
},
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