Skip to content

Instantly share code, notes, and snippets.

@aurerua
Last active December 10, 2019 17:17
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 aurerua/d0423abd64e0693bddfcfd83db9a96a6 to your computer and use it in GitHub Desktop.
Save aurerua/d0423abd64e0693bddfcfd83db9a96a6 to your computer and use it in GitHub Desktop.
XState simple machine
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
/*
States:
- ground
- ladder
- topOfSlide
Events:
- CLIMB_UP
- CLIMB_DOWN
- SLIDE
*/
const myMachine = Machine({
id: 'slide',
initial: 'ground',
states: {
ground: {
on: {
CLIMB_UP: 'ladder'
}
},
ladder: {
on:{
CLIMB_UP: 'topOfSlide',
CLIMB_DOWN: 'ground'
}
},
topOfSlide: {
on:{
SLIDE: 'ground' ,
CLIMB_DOWN: 'ladder'
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment