Last active
October 8, 2020 13:30
-
-
Save vojtaholik/96344a7bc15219b4834453aaeb080b3f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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
// 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