Skip to content

Instantly share code, notes, and snippets.

@scarabaeus
Created March 28, 2022 00:03
Show Gist options
  • Save scarabaeus/8724f538c2bab408dc35232afe1bb3f0 to your computer and use it in GitHub Desktop.
Save scarabaeus/8724f538c2bab408dc35232afe1bb3f0 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'Shopping Cart Checkout',
initial: 'SERVICE_CALL',
context: {},
states: {
'SERVICE_CALL': {
invoke: {
id: 'getData',
src: 'getMockData',
onDone: {
target: 'TRANSIENT_PAGE',
actions: ['APPLICATION.REFRESH'],
},
onError: {
target: 'ERROR_PAGE',
actions: ['APPLICATION.REFRESH'],
},
},
},
'TRANSIENT_PAGE': {
after: {
1500: [
{
target: 'CART_MAIN_PAGE',
actions: ['buildItemsList', 'APPLICATION.REFRESH'],
},
],
},
},
'CART_MAIN_PAGE': {
on: {
SHIPPING: {
target: 'SHIPPING_ADDRESS',
actions: ['buildItemsList'],
},
},
},
'SHIPPING_ADDRESS': {
on: {
PAYMENT: {
target: 'PAYMENT_METHOD',
actions: ['saveShippingData'],
},
CART: {
target: 'CART_MAIN_PAGE',
actions: [],
},
},
},
'PAYMENT_METHOD': {
on: {
'CREDIT CARD': {
target: 'CREDIT_CARD_DETAILS',
actions: ['setPaymentMethod'],
},
PAYPAL: {
target: 'PAYPAL_DETAILS',
actions: ['setPaymentMethod'],
},
},
},
'CREDIT_CARD_DETAILS': {
on: {
BILLING: {
target: 'BILLING_ADDRESS',
actions: [],
},
PAYMENT: {
target: 'PAYMENT_METHOD',
actions: [],
},
},
},
'BILLING_ADDRESS': {
on: {
'REVIEW ORDER': {
target: 'ORDER_REVIEW',
actions: ['saveBillingData'],
},
'CREDIT CARD': {
target: 'CREDIT_CARD_DETAILS',
actions: [],
},
},
},
'ORDER_REVIEW': {
on: {
'SUBMIT ORDER': {
target: 'SUCCESS_PAGE',
actions: ['chargePaymentMethod', 'processOrder'],
},
SHIPPING: {
target: 'SHIPPING_ADDRESS',
actions: [],
},
BILLING: {
target: 'BILLING_ADDRESS',
actions: [],
},
PAYMENT: {
target: 'CREDIT_CARD_DETAILS',
actions: [],
},
ERROR: {
target: 'ERROR_PAGE',
},
},
},
'PAYPAL_DETAILS': {
on: {
'REVIEW ORDER': {
target: 'ORDER_REVIEW',
actions: [],
},
},
},
'SUCCESS_PAGE': {
type: 'final',
},
'ERROR_PAGE': {
on: {},
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment