Last active
May 11, 2020 19:23
-
-
Save m1010j/143d344b29e1b4fb364bb521d28d0fae 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
const questionMachine = Machine( | |
{ | |
id: 'question', | |
initial: '072ecdc1-be12-4f8f-9707-15e4dd53ccc0', | |
context: { | |
currentStep: 0, | |
totalNumberOfSteps: 2, | |
followUpQuestionStep: 0, | |
}, | |
states: { | |
'072ecdc1-be12-4f8f-9707-15e4dd53ccc0': { | |
on: { | |
ANSWER: [ | |
{ | |
target: '8cdb1cb2-b06d-42c8-b1e6-17058dad9b26', | |
cond: { type: 'eventValueIsCondValue', value: 'Yes' }, | |
actions: 'incrementFollowUpQuestionStep' | |
}, | |
{ | |
target: '0739db84-54c8-4543-b74d-3e0625bcb463', | |
actions: 'incrementCurrentStep', | |
}, | |
], | |
}, | |
}, | |
'8cdb1cb2-b06d-42c8-b1e6-17058dad9b26': { | |
on: { | |
ANSWER: { | |
target: '0739db84-54c8-4543-b74d-3e0625bcb463', | |
actions: 'incrementCurrentStep', | |
}, | |
}, | |
}, | |
'0739db84-54c8-4543-b74d-3e0625bcb463': { | |
on: { | |
ANSWER: { | |
target: 'complete', | |
actions: 'incrementCurrentStep', | |
} | |
}, | |
}, | |
complete: { | |
type: 'final', | |
}, | |
}, | |
}, | |
{ | |
guards: { | |
eventValueIsCondValue: (_, event, { cond }) => event.value === cond.value, | |
}, | |
actions: { | |
incrementFollowUpQuestionStep: assign({followUpQuestionStep: (context) => context.followUpQuestionStep + 1}), | |
incrementCurrentStep: assign({currentStep: (context) => context.currentStep + 1, followUpQuestionStep: 0}) | |
} | |
}, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment