Skip to content

Instantly share code, notes, and snippets.

@danielkcz
Created November 12, 2019 20:10
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 danielkcz/b011ec681aaf7b9270d762d2969458c6 to your computer and use it in GitHub Desktop.
Save danielkcz/b011ec681aaf7b9270d762d2969458c6 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({
initial: 'slide',
states: {
slide: {
id: 'slide',
initial: 'ground',
states: {
ground: {
on: {
CLIMB_UP: 'ladder'
}
},
ladder: {
initial: 'step1',
states: {
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'
}
},
hist: {
type: 'history',
history: 'deep'
}
},
on: {
FLY: '#flying'
}
},
flying: {
id: 'flying',
activities: "yell",
on: {
LAND: 'slide.hist'
},
}
},
}, {
activities: {
yell: (ctx) => {
const interval = setInterval(() => console.log("LOOK AT ME!"), 1000)
return () => clearInterval(interval)
}
}
});
// Write "LOOK AT ME!" every second to the console when in the flying state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment