Skip to content

Instantly share code, notes, and snippets.

@MarkLopresto
Last active August 24, 2021 00:52
Show Gist options
  • Select an option

  • Save MarkLopresto/50212efd678c7851f0c1988965de041f to your computer and use it in GitHub Desktop.

Select an option

Save MarkLopresto/50212efd678c7851f0c1988965de041f 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 lightBulbMachine = Machine({
id: 'lightbulb',
initial: 'unlit',
states: {
lit: {
on: {
BREAK: {
target: 'broken',
actions: ['logBroken']
},
TOGGLE: 'unlit'
}
},
unlit: {
on: {
BREAK: {
target: 'broken',
actions: ['logBroken']
},
TOGGLE: 'lit'
}
},
broken: {}
}
}, {
actions: {
logBroken: (context, event) => { console.log(`I am broke in the ${event.location}`)}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment