Last active
September 26, 2020 05:41
-
-
Save abhaysood/c04ec4fcccc8615ce1eb5bb79c2a88c5 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
const summaryState = { | |
type: 'parallel', | |
initial: 'loadOrder', | |
states: { | |
loadOrder: { | |
initial: 'loadingOrder', | |
states: { | |
idle: {}, | |
loadingOrder: { | |
on: { | |
SUCCESS: 'idle', | |
ERROR: 'errorLoadingOrder' | |
} | |
}, | |
errorLoadingOrder: { | |
on: { | |
RETRY: 'loadingOrder' | |
} | |
} | |
} | |
}, | |
completeOrder: { | |
initial: 'idle', | |
states: { | |
idle: { | |
}, | |
completingOrder: { | |
on: { | |
SUCCESS: 'idle', | |
ERROR: 'idle' | |
} | |
}, | |
} | |
}, | |
cancelOrder: { | |
initial: 'idle', | |
states: { | |
idle: {}, | |
cancellingOrder: { | |
on: { | |
SUCCESS: 'idle', | |
ERROR: 'idle' | |
} | |
}, | |
} | |
}, | |
}, | |
on: { | |
COMPLETE_ORDER: 'summary.completeOrder.completingOrder', | |
CANCEL_ORDER: 'summary.cancelOrder.cancellingOrder' | |
} | |
}; | |
const priceCalculationState = { | |
initial: 'idle', | |
states: { | |
idle: {}, | |
calculatingPrice: { | |
on: { | |
SUCCESS: 'idle', | |
ERROR: 'calculatingPriceError', | |
NO_ITEMS_ADDED: 'idle' | |
} | |
}, | |
calculatingPriceError: { | |
on:{ | |
RETRY: 'calculatingPrice' | |
} | |
} | |
} | |
}; | |
const paymentSelectionState = { | |
initial: 'none', | |
states: { | |
none: {}, | |
selected: {} | |
} | |
}; | |
const createOrderState = { | |
initial: 'idle', | |
states: { | |
idle: {}, | |
creatingOrder: { | |
on: { | |
SUCCESS: 'idle', | |
ERROR: 'errorCreatingOrder', | |
}, | |
}, | |
errorCreatingOrder: {} | |
}, | |
}; | |
const checkoutState = { | |
type: 'parallel', | |
initial: 'priceCalculation', | |
on: { | |
QUANTITY_CHANGED: 'checkout.priceCalculation.calculatingPrice', | |
PAYMENT_SELECTED: 'checkout.paymentSelection.selected', | |
CREATE_ORDER: 'checkout.createOrder.creatingOrder' | |
}, | |
states: { | |
priceCalculation : { | |
...priceCalculationState | |
}, | |
createOrder : { | |
...createOrderState | |
}, | |
paymentSelection: { | |
...paymentSelectionState | |
} | |
}, | |
}; | |
const newOrderState = { | |
initial: 'loadingMenu', | |
states: { | |
loadingMenu: { | |
on: { | |
SUCCESS: 'checkout', | |
ERROR: 'errorLoadingMenu' | |
} | |
}, | |
errorLoadingMenu: { | |
on:{ | |
RETRY: 'loadingMenu' | |
} | |
}, | |
checkout: { | |
...checkoutState | |
} | |
}, | |
on: { | |
ORDER_CREATED_PAID: 'summary', | |
ORDER_CREATED_UNPAID: 'payment' | |
} | |
} | |
const paymentState = { | |
initial: 'idle', | |
states: { | |
idle: {} | |
} | |
}; | |
const manualOrderStates = Machine({ | |
key: 'orders', | |
initial: 'init', | |
states: { | |
init: { | |
on: { | |
NEW_ORDER: 'newOrder', | |
PAID_ORDER: 'summary', | |
UNPAID_ORDER: 'payment', | |
}, | |
}, | |
newOrder: { | |
...newOrderState | |
}, | |
summary : { | |
...summaryState | |
}, | |
payment : { | |
...paymentState | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment