Skip to content

Instantly share code, notes, and snippets.

@jasonleonhard
Created April 3, 2020 22:42
Show Gist options
  • Save jasonleonhard/fcb2e1df208994aad1edcefd717df135 to your computer and use it in GitHub Desktop.
Save jasonleonhard/fcb2e1df208994aad1edcefd717df135 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const lifeMachine = Machine({
id: 'life',
initial: 'alive',
context: {
retries: 0
},
states: {
alive: {
on: {
KILL: 'dying'
}
},
dying: {
on: {
RESUSCITATE: 'alive',
PRONOUNCE: 'dead'
}
},
dead: {
on: {
RETRY: {
target: 'dying',
actions: assign({
retries: (context, event) => context.retries + 1
})
},
REINCARNATE: {
target: 'alive',
},
TRANSITION: {
target: 'afterlife',
},
}
},
afterlife: {
on: {
GOOD: 'heaven',
BAD: 'hell',
NEUTRAL: 'limbo',
}
},
limbo: {
on: {
GOOD: 'heaven',
BAD: 'hell',
}
},
heaven: {
on: {
GOOD: 'heaven',
BAD: 'hell',
}
},
hell: {
on: {
GOOD: 'heaven',
BAD: 'hell',
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment