Skip to content

Instantly share code, notes, and snippets.

@FilDevTronic
Created November 12, 2019 18:28
Show Gist options
  • Save FilDevTronic/59dc9c68059480e272956977d770c2d8 to your computer and use it in GitHub Desktop.
Save FilDevTronic/59dc9c68059480e272956977d770c2d8 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 myMachine = Machine({
id: 'slide',
initial: 'ground',
states: {
ground: {
on: {
CLIMB_UP: 'ladder'
}
},
ladder: {
initial: 'entering',
states: {
entering: {
on: {
'': [
{
target: 'step2',
cond: 'isJumping'
},
{
target: 'step1'
}
]
}
},
step1: {
on: {
CLIMB_UP: 'step2',
CLIMB_DOWN: '#slide.ground'
}
},
step2: {
on: {
CLIMB_UP: '#slide.topOfSlide',
CLIMB_DOWN: 'step1'
}
},
}
},
topOfSlide: {
on: {
CLIMB_DOWN: 'ladder.step2',
SLIDE: 'ground'
}
},
}
}, {
guards: {
isJumping: () => true
}
})
// Add step1 and step2 subStates to ladder
// CLIMB_UP and CLIMB_DOWN should move between those states
// CLIMB_UP from step2 should move to topOfSlide
// CLIMB_DOWN from topOfSlide should move to step2
// Add an isJumping guard that returns true
// Change CLIMB_UP from ground to trigger multiple transitions
// if isJumping then go to step2
// otherwise go to step1
// Refactor so the ground CLIMB_UP transition just goes to ladder
// Add an initial entering state for ladder that has an automatic transition to either step1 or step2 based on the isJumping guard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment