Skip to content

Instantly share code, notes, and snippets.

@AndresRodH
Last active August 20, 2020 18:18
Show Gist options
  • Save AndresRodH/7e60a11c4c69118e000b9b94d274ab3e to your computer and use it in GitHub Desktop.
Save AndresRodH/7e60a11c4c69118e000b9b94d274ab3e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const guidelinesMachine = Machine({
id: 'feeding-guidelines',
context: {
currentDietId: null,
},
initial: 'idle',
states: {
idle: {
on: {
PICK_RECOMMENDED_DIET: 'pickRecommendedDiets',
MANUAL_SEARCH: 'manualSearch',
},
},
pickRecommendedDiets: {
on: {
MANUAL_SEARCH: 'manualSearch',
SELECT_DIET: {
target: 'idle',
actions: 'setCurrentDiet',
},
},
},
manualSearch: {
context: {
product: null,
brand: null,
},
initial: 'brand',
on: {
PICK_RECOMMENDED_DIET: '#feeding-guidelines.pickRecommendedDiets',
},
states: {
brand: {
on: {
SET_BRAND: {
target: 'product',
actions: 'setBrand',
},
},
},
product: {
on: {
SELECT_DIET: {
target: 'ready',
actions: 'setCurrentDiet',
},
SET_BRAND: {
target: 'product',
actions: 'setBrand',
},
},
},
ready: {
type: 'final',
},
},
onDone: {
target: 'idle',
actions: 'setCurrentDiet',
},
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment