Skip to content

Instantly share code, notes, and snippets.

@zsimo
Created December 17, 2019 13:28
Show Gist options
  • Save zsimo/fa81ee81e82b0620d8a477ab4cbdbe7b to your computer and use it in GitHub Desktop.
Save zsimo/fa81ee81e82b0620d8a477ab4cbdbe7b 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 lightMachine = Machine({
key: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: 'yellow'
}
},
yellow: {
on: {
TIMER: 'red'
}
},
red: {
initial: 'walk',
// the 'activateCrosswalkLight' activity is started upon entering
// the 'light.red' state, and stopped upon exiting it.
activities: ['activateCrosswalkLight'],
on: {
TIMER: 'green'
},
states: {
walk: { on: { PED_WAIT: 'wait' } },
wait: {
// the 'blinkCrosswalkLight' activity is started upon entering
// the 'light.red.wait' state, and stopped upon exiting it
// or its parent state.
activities: ['blinkCrosswalkLight'],
on: { PED_STOP: 'stop' }
},
stop: {}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment