Last active
April 12, 2020 11:27
-
-
Save fdjones/d00e26bd32c0231a9f1fcab898c0d148 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
function fetchQuestions() { | |
return Promise.resolve([ | |
{ name: 'bob' }, | |
{ name: 'bill' }, | |
{ name: 'mary' } | |
]); | |
} | |
const test = Machine({ | |
id: 'test', | |
initial: 'idle', | |
context: { | |
questions: [], | |
error: '' | |
}, | |
states: { | |
idle: { | |
on: { | |
START_TEST: 'fetchingQuestions' | |
} | |
}, | |
fetchingQuestions: { | |
on: { | |
EXIT_TEST: 'exit' | |
}, | |
invoke: { | |
id: 'fetchQuestions', | |
src: () => fetchQuestions, | |
onDone: { | |
target: 'answeringQuestion', | |
actions: assign({ questions: (ctx, event) => event.data}) | |
}, | |
onError: { | |
target: 'error', | |
actions: assign({ questions: (ctx, event) => event.data}) | |
} | |
} | |
}, | |
answeringQuestion: { | |
on: { | |
SUBMIT_ANSWER: 'viewingAnwer', | |
EXIT_TEST: 'exit' | |
}, | |
}, | |
viewingAnwer: { | |
on: { | |
NEXT_QUESTION: 'answeringQuestion', | |
FINISH_TEST: 'reviewingTest', | |
EXIT_TEST: 'exit' | |
} | |
}, | |
reviewingTest: { | |
on: { | |
EXIT_TEST: 'exit' | |
} | |
}, | |
error: {}, | |
exit: { | |
type: 'final' | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment