Skip to content

Instantly share code, notes, and snippets.

@georgefeast
Created April 18, 2020 22:33
Show Gist options
  • Save georgefeast/3ee9f437e1230e7f552f41a7d3a4d873 to your computer and use it in GitHub Desktop.
Save georgefeast/3ee9f437e1230e7f552f41a7d3a4d873 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: "shopping-cart",
initial: "pre-order",
states: {
"pre-order": {
on: {
START_NEW_ORDER: "ordering"
}
},
ordering: {
type: "parallel",
on: {
CANCEL_ORDER: "cancelled",
},
states: {
"browsing-products": {
initial: "no-items",
states: {
"no-items": {
on: {
ADD_ITEM: {actions: ["addCartItem"]},
}
},
"has-items": {
on: {
ADD_ITEM: {actions: ["addCartItem"]},
REMOVE_ITEM: {actions: ["removeCartItem"]},
REVIEW_ORDER: "#shopping-cart.ordering.reviewing-order.open",
}
}
}
},
"inspecting-product": {
initial: "closed",
states: {
closed: {
on: {
OPEN_DIALOG: "open"
}
},
open: {
on: {
CLOSE_DIALOG: "closed",
ADD_ITEM: { actions: ["addCartItem"]},
REMOVE_ITEM: { actions: ["removeCartItem"]},
}
},
}
},
"reviewing-order": {
initial: "closed",
states: {
closed: {
on: {
REVIEW_ORDER: "open"
}
},
open: {
on: {
CONFIRM: "#shopping-cart.success",
BACK: "closed",
SET_PICKUP_TIME: {actions: ["setPickupTime"]},
ADD_ITEM: {actions: ["addCartItem"]},
REMOVE_ITEM: {actions: ["removeCartItem"]},
}
},
}
}
}
},
success: {
type: "final"
},
cancelled: {},
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment