Skip to content

Instantly share code, notes, and snippets.

@matthewmorek
Created January 2, 2021 12:08
Show Gist options
  • Select an option

  • Save matthewmorek/39326957612a979ea9e80121a197d00c to your computer and use it in GitHub Desktop.

Select an option

Save matthewmorek/39326957612a979ea9e80121a197d00c 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 fetchMachine = Machine({
id: "form",
initial: "selectCountry",
context: {
tab: null,
},
states: {
selectCountry: {
on: {
CONTINUE: "selectFund",
},
},
selectFund: {
on: {
CONTINUE: "selectAmount",
},
},
selectAmount: {
on: {
CONTINUE: "enterDetails",
},
},
enterDetails: {
on: {
CONTINUE: "enterPayment",
},
},
enterPayment: {
on: {
CONFIRM: "processingPayment",
},
},
processingPayment: {
onEntry: ["SHOW_ACTIVITY", "SUBMIT_DATA"],
on: {
SUCCESS: "paymentComplete",
FAILURE: "paymentFailure",
},
onExit: ["HIDE_ACTIVITY"],
},
paymentComplete: {
on: {
RESET: "selectCountry",
},
},
paymentFailure: {
on: {
RETRY: "enterPayment",
},
},
},
on: {
SWITCH: [
{
target: "selectCountry",
cond: (context, event) => event.state == "selectCountry",
},
{
target: "selectFund",
cond: (context, event) => event.state == "selectFund",
},
{
target: "selectAmount",
cond: (context, event) => event.state == "selectAmount",
},
{
target: "enterDetails",
cond: (context, event) => event.state == "enterDetails",
},
{
target: "enterPayment",
cond: (context, event) => event.state == "enterPayment",
},
],
},
},);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment