Last active
April 27, 2020 00:23
-
-
Save ecancino/c77ca27215f1c2d69f75be2d35abfd6e 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 delay = timer => ctx => | |
| ctx.multiplier * timer | |
| const stoplight = Machine({ | |
| id: "stoplight", | |
| strict: true, | |
| context: { | |
| multiplier: 2 | |
| }, | |
| on: { | |
| INC_MULTIPLIER: { | |
| actions: ['rushHour'] | |
| } | |
| }, | |
| initial: 'red', | |
| states: { | |
| green: { | |
| after: { | |
| GREEN_TIMER: 'yellow' | |
| } | |
| }, | |
| yellow: { | |
| after: { | |
| YELLOW_TIMER: 'red' | |
| } | |
| }, | |
| red: { | |
| after: { | |
| RED_TIMER: 'green' | |
| } | |
| } | |
| } | |
| }, { | |
| actions: { | |
| rushHour: assign({ | |
| multiplier: ctx => ctx.multiplier + 1 | |
| }) | |
| }, | |
| delays: { | |
| GREEN_TIMER: delay(3000), | |
| YELLOW_TIMER: delay(1000), | |
| RED_TIMER: delay(4000), | |
| } | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment