Last active
September 17, 2021 12:06
-
-
Save xgenvn/ea450aed6ca711b41c4d030b8ff199a9 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const askAnswerMachine = Machine({ | |
id: 'askAnswer', | |
initial: 'idle', | |
context: { | |
questions: [], | |
last_question_index: 0 | |
}, | |
states: { | |
idle: { | |
on: { | |
START: 'welcome' | |
} | |
}, | |
welcome: { | |
on: { | |
NEXT_INPUT: 'ask_question' | |
} | |
}, | |
show_question: { | |
on: { | |
FINAL_QUESTION: 'wait_for_submit', | |
QUESTION_SHOWED: 'waiting_answer' | |
} | |
}, | |
waiting_answer: { | |
on: { | |
ANSWER_VALID: { | |
target: 'ask_question', | |
actions: assign({ | |
last_question_index: (context, event) => context.last_question_index + 1 | |
}) | |
}, | |
ANSWER_INVALID: 'ask_question' | |
} | |
}, | |
wait_for_submit: { | |
on: { | |
SUBMIT: 'finish', | |
CANCEL: 'submit_cancel', | |
} | |
}, | |
show_menu: { | |
on: { | |
} | |
}, | |
finish: { | |
}, | |
submit_cancel: { | |
} | |
// failure: { | |
// on: { | |
// RETRY: { | |
// target: 'loading', | |
// actions: assign({ | |
// retries: (context, event) => context.retries + 1 | |
// }) | |
// } | |
// } | |
// } | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment