Skip to content

Instantly share code, notes, and snippets.

@xgenvn
Last active September 17, 2021 12:06
Show Gist options
  • Save xgenvn/ea450aed6ca711b41c4d030b8ff199a9 to your computer and use it in GitHub Desktop.
Save xgenvn/ea450aed6ca711b41c4d030b8ff199a9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// 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