Skip to content

Instantly share code, notes, and snippets.

@alveshelio
Last active November 29, 2020 18:05
Show Gist options
  • Save alveshelio/fdf164d2d12ad6e13dddf8aa58b32776 to your computer and use it in GitHub Desktop.
Save alveshelio/fdf164d2d12ad6e13dddf8aa58b32776 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const lit = {
on: {
BREAK: {
target: 'broken',
actions: () => console.warn('transition to onBreak')
},
TOGGLE: 'unlit',
},
exit: () => console.warn("it's dark and cold")
}
const unlit = {
on: {
BREAK: 'broken',
TOGGLE: 'lit'
},
}
const broken = {
entry: ['logBroken']
}
const states = { lit, unlit, broken }
const initial = 'unlit'
const config = {
id: 'lightBulb',
initial,
states,
strict: true,
devTools: true,
}
const lightBulbMachine = Machine(config, {
actions: {
logBroken: (context, event) => console.warn(`yo I'm broken in the ${event.location}`)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment