Skip to content

Instantly share code, notes, and snippets.

@sebabouche
Last active April 5, 2021 17:18
Show Gist options
  • Save sebabouche/2df027545db58e41216a88c765e9998a to your computer and use it in GitHub Desktop.
Save sebabouche/2df027545db58e41216a88c765e9998a 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',
context: {
switches: 0
},
states: {
unlit: {
on: {
TOGGLE: 'lit',
BREAK: "broken"
}
},
lit: {
exit: ["logUnlitExit"],
on: {
TOGGLE: 'unlit',
BREAK: {
target: "broken",
actions: [() => {
console.log("Transitionning to BREAK state.")
}]
}
}
},
broken: {
entry: ["logBroken"],
type: 'final'
},
}
}, {
actions: {
logBroken: (context, event) => {
console.log(`Yo I am broke in the ${event.location}.`)
},
logUnlitExit: () => { return console.log("Light is off.")
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment