Last active
October 15, 2020 15:44
-
-
Save codingedgar/1ef232e89499661fc668d9984d8ac4d6 to your computer and use it in GitHub Desktop.
example1 state machine
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 = Machine<Context, Scheme, Event>({ | |
| strict: true, | |
| initial: 'X', | |
| context: DEFAULT_CONTEXT, | |
| states: { | |
| X: { | |
| always: { | |
| cond: CONDITIONS.IS_DONE, | |
| target: 'DONE', | |
| }, | |
| on: { | |
| PLAYED: { | |
| cond: CONDITIONS.IS_VALID_PLAY, | |
| target: 'O', | |
| actions: [ | |
| ACTIONS.ASSIGN_MATCH_SCORE('X'), | |
| ACTIONS.ASSIGN_BOARD('X'), | |
| ], | |
| }, | |
| }, | |
| }, | |
| O: { | |
| always: { | |
| cond: CONDITIONS.IS_DONE, | |
| target: 'DONE', | |
| }, | |
| on: { | |
| PLAYED: { | |
| cond: CONDITIONS.IS_VALID_PLAY, | |
| target: 'X', | |
| actions: [ | |
| ACTIONS.ASSIGN_MATCH_SCORE('O'), | |
| ACTIONS.ASSIGN_BOARD('O'), | |
| ], | |
| }, | |
| }, | |
| }, | |
| DONE: { | |
| on: { | |
| RESTARTED: { | |
| target: 'X', | |
| actions: [ | |
| ACTIONS.ASSIGN_DEFAULT_CONTEXT, | |
| ] | |
| } | |
| } | |
| }, | |
| }, | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment