Last active
April 5, 2021 17:18
-
-
Save sebabouche/2df027545db58e41216a88c765e9998a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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