Skip to content

Instantly share code, notes, and snippets.

@eveporcello
Created September 8, 2020 22:19
Show Gist options
  • Save eveporcello/f6666062e5f52aa63ab128412f385054 to your computer and use it in GitHub Desktop.
Save eveporcello/f6666062e5f52aa63ab128412f385054 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const cocktailMachine = Machine({
id: 'cocktail',
initial: 'empty',
context: {
ingredients: []
},
states: {
empty: {
on: {
FIRST_INGREDIENT: {
target: 'mixing',
actions: assign({
addFirstIngredient: (context, event) => context.ingredients.push(event.payload)
})
}
}
},
mixing: {
on: {
STIR: 'combining',
SHAKE: 'combining',
MISPOUR: {
target: 'empty',
actions: assign({
emptyIngredients: (context, event) => context.ingredients = []
})
},
ADD_INGREDIENT: {
target: 'mixing',
actions: assign({
addIngredients: (context, event) => context.ingredients.push(event.payload)
})
}
}
},
combining: {
on: {
TASTE: 'tasteTest'
}
},
tasteTest: {
on: {
IS_GOOD: 'drink',
IS_BAD: 'empty'
}
},
drink: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment