Last active
April 26, 2020 06:02
-
-
Save ecancino/def278e5091b3351072d2bd8622b02e5 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
| // const { Machine, interpret } = require("xstate"); | |
| const lit = { | |
| on: { | |
| BREAK: "broken", | |
| TOGGLE: "unlit" | |
| } | |
| }; | |
| const unlit = { | |
| on: { | |
| BREAK: "broken", | |
| TOGGLE: "lit" | |
| } | |
| }; | |
| const broken = { | |
| type: "final", | |
| entry: ['logBroken'] | |
| }; | |
| const states = { lit, unlit, broken }; | |
| const initial = "unlit"; | |
| const config = { | |
| id: "lightBulb", | |
| strict: true, | |
| initial, | |
| states | |
| }; | |
| const lightBulb = Machine(config, { | |
| actions: { | |
| logBroken: (ctx, evt) => | |
| console.log(` | |
| YO! I am broken in the ${evt.location} | |
| `) | |
| } | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment