Skip to content

Instantly share code, notes, and snippets.

@Lorezz
Created February 9, 2021 14:19
Show Gist options
  • Save Lorezz/e5b0b3468ac6a76da1150ec18ee57187 to your computer and use it in GitHub Desktop.
Save Lorezz/e5b0b3468ac6a76da1150ec18ee57187 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 saveOrder = assign({
order: (context, event) => event.data,
});
function hasCustomer(context, event) {
return envent.customer_email != null;
}
const checkoutMachine = Machine(
{
id: 'checkout',
initial: 'fetch_order',
context: {
order: null,
},
states: {
fetch_order: {
on: {
RECEIVED: [
{
target: 'choose_address',
cond: hasCustomer,
actions: saveOrder,
},
{
target: 'create_address',
actions: saveOrder,
},
],
},
},
create_address: {
on: {
DONE: 'choose_address',
actions: saveOrder,
},
},
choose_address: {
on: {
DONE: {
target: 'choose_payment',
actions: saveOrder,
},
NEW: 'create_address',
},
},
choose_payment: {
on: {
DONE: {
target: 'payment',
actions: saveOrder,
},
},
},
payment: {
on: {
DONE: {
target: 'place',
actions: saveOrder,
},
CHANGE: 'choose_payment',
},
},
place: {
type: 'final',
},
},
},
{
actions: {
saveOrder,
},
guards: {
hasCustomer,
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment