Last active
December 21, 2020 07:20
-
-
Save coma/f5db01e1b2c0bb43de7c8344752fb997 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 isStatus = (status) => (context, event) => { | |
return context.user && event.status === status; | |
}; | |
const gameMachine = Machine({ | |
id: 'game', | |
initial: 'connecting', | |
context: { | |
user: "123abc", | |
}, | |
states: { | |
connecting: { | |
on: { | |
connect: [ | |
{ | |
target: 'waiting', | |
cond: isStatus('waiting'), | |
}, | |
{ | |
target: 'register', | |
}, | |
], | |
} | |
}, | |
register: { | |
on: { | |
waiting: 'waiting', | |
question: 'question', | |
answer: 'answer', | |
results: 'results', | |
winners: 'winners', | |
} | |
}, | |
waiting: { | |
on: { | |
next: 'question' | |
} | |
}, | |
question: { | |
on: { | |
next: 'answer' | |
} | |
}, | |
answer: { | |
on: { | |
answer: 'answered', | |
next: 'results' | |
} | |
}, | |
answered: { | |
on: { | |
next: 'results' | |
} | |
}, | |
results: { | |
on: { | |
question: 'question', | |
next: 'winners' | |
} | |
}, | |
winners: { | |
type: 'final' | |
}, | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment