Skip to content

Instantly share code, notes, and snippets.

@vojtaholik
Last active October 8, 2020 13:30
Show Gist options
  • Save vojtaholik/96344a7bc15219b4834453aaeb080b3f to your computer and use it in GitHub Desktop.
Save vojtaholik/96344a7bc15219b4834453aaeb080b3f 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 quizMachine = Machine({
id: 'question',
initial: 'answering',
context: {
currentQuestion: 0,
showAnswer: false,
answer: null
},
states: {
answering: {
on: {
SUBMIT: 'answer',
}
},
answer: {
invoke: {
id: "submitAnswer",
onDone: {
target: "answered",
actions: assign({
answer: (context, event) => context,
showAnswer: true
})
},
onError: {
target: 'failure'
}
},
},
answered: {
type: "final",
on: {
CONTINUE: 'answering'
}
},
failure: {
on: {
RETRY: 'answer',
START_OVER: 'answering',
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment