Skip to content

Instantly share code, notes, and snippets.

@mogarick
Last active April 19, 2021 22:38
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 mogarick/b94df84c216ec760f3a8a0dfd998c5d2 to your computer and use it in GitHub Desktop.
Save mogarick/b94df84c216ec760f3a8a0dfd998c5d2 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const lightMachine = Machine({
// not a parallel machine
id: 'light',
initial: 'green',
states: {
green: {
on: { TIMER: 'yellow' }
},
yellow: {
on: { TIMER: 'red' }
},
// nested parallel machine
red: {
type: 'parallel',
on:{
TIMER: {target: 'green'}},
states: {
walkSign: {
initial: 'solid',
states: {
solid: {
on: { TIMER: 'turned_off'},
on: { COUNTDOWN: 'flashing' },
},
flashing: {
on: { STOP_COUNTDOWN: 'turned_off' }
},
turned_off: {
type:'final'
}
}
},
pedestrian: {
initial: 'walk',
states: {
walk: {
on: { COUNTDOWN: 'wait' }
},
wait: {
on: { STOP_COUNTDOWN: 'stop' }
},
stop: {
type: 'final'
}
}
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment