Skip to content

Instantly share code, notes, and snippets.

@codingedgar
Last active October 15, 2020 15:44
Show Gist options
  • Select an option

  • Save codingedgar/1ef232e89499661fc668d9984d8ac4d6 to your computer and use it in GitHub Desktop.

Select an option

Save codingedgar/1ef232e89499661fc668d9984d8ac4d6 to your computer and use it in GitHub Desktop.
example1 state machine
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