Skip to content

Instantly share code, notes, and snippets.

@adamkl
Last active October 8, 2020 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamkl/f8896d37d49e5d8d5e481a0d246d2358 to your computer and use it in GitHub Desktop.
Save adamkl/f8896d37d49e5d8d5e481a0d246d2358 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 fetchMachine = Machine({
id: 'cookie_machine',
initial: 'idle',
context: {
cookies: 0
},
states: {
idle: {
on: {
ADD_DRY_INGREDIENTS: 'dry_ingredients_added'
}
},
dry_ingredients_added: {
on: {
ADD_CHOCOLATE_CHIPS: 'chocolate_chips_added'
}
},
chocolate_chips_added: {
on: {
ADD_WET_INGREDIENTS: 'all_ingredients_added'
}
},
all_ingredients_added: {
on: {
MIX: 'mixing'
}
},
mixing: {
on: {
DONE: 'prep_complete'
}
},
prep_complete: {
on: {
PORTION_COOKIES:
'portioning_complete'
}
},
portioning_complete: {
on: {
BAKE: 'baking'
}
},
baking: {
on: {
DONE: {
target: 'cooling',
actions: assign({
cookies: 12
})
}
}
},
cooling: {
on: {
COOL: 'ready'
}
},
ready: {
on: {
EAT: [{
target: 'ready',
cond: ({cookies}) => cookies > 0,
actions: assign({
cookies: ({cookies}) => cookies - 1
})
},
{
target: 'idle'
}]
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment