Skip to content

Instantly share code, notes, and snippets.

@coma
Last active December 21, 2020 07:20
Show Gist options
  • Save coma/f5db01e1b2c0bb43de7c8344752fb997 to your computer and use it in GitHub Desktop.
Save coma/f5db01e1b2c0bb43de7c8344752fb997 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// 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