Skip to content

Instantly share code, notes, and snippets.

@saschwarz
Last active March 9, 2020 13:40
Show Gist options
  • Save saschwarz/2ad7eeda381f43a4139c01df82d2a9ad to your computer and use it in GitHub Desktop.
Save saschwarz/2ad7eeda381f43a4139c01df82d2a9ad to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const dogPlay = Machine({
id: 'dogplay',
initial: 'sleeping',
context: {
doorOpen: false,
},
states: {
sleeping: {
on: {
LETS_PLAY: 'standing'
}
},
standing: {
on: {
SIT: 'sitting'
}
},
sitting: {
on: {
STAND: 'standing',
FREE: [
{
target: 'outside',
cond: 'doorIsOpen',
},
{ target: 'standing' }],
},
},
outside: {
},
},
on: {
DOOR_OPEN: {
actions: [
assign({doorOpen: _ => true})
],
},
DOOR_CLOSE: {
actions: [
assign({doorOpen: _ => false})
]
},
}
},
{
guards: {
doorIsOpen: (context, event) => context.doorOpen
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment