Created
October 20, 2020 08:05
-
-
Save vojtaholik/8712f0c4e5643a706d5d9145225a8340 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
| const quizMachine = Machine({ | |
| id: 'question', | |
| initial: 'idle', | |
| context: { | |
| questions: [{title: "question 1", title: "question 2", id: 'question-1'}], | |
| currentQuestionId: 'question-1', | |
| answers: [] | |
| }, | |
| states: { | |
| idle: { | |
| on: { | |
| SUBMIT: { | |
| target: "answering", | |
| actions: assign({answers: (context, event) => { | |
| const {answers} = context | |
| return [...answers, event.answer] | |
| }}) | |
| } | |
| } | |
| }, | |
| answering: { | |
| // invoke: { | |
| // id: 'postingAnswer', | |
| // src: (context, _event) => { | |
| // const {ansers, currentQuestionId} = context | |
| // // find(answers, {questionId: currentQuestionId}) | |
| // // return axios.post() | |
| // } | |
| // onDone: {target: 'answered'}, | |
| // onError: {target: 'failure'} | |
| // } | |
| on: {'': [{target: 'answered'}]}, | |
| }, | |
| answered: { | |
| on: { | |
| NEXT_QUESTION: {target: 'idle', actions: assign({currentQuestionId: (context, event) => { | |
| return event.currentQuestionId | |
| }})} | |
| } | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment