Skip to content

Instantly share code, notes, and snippets.

@lifedraft
Last active January 17, 2020 15:20
Show Gist options
  • Save lifedraft/bfec5a2ac752ed188b96bf5bac883acb to your computer and use it in GitHub Desktop.
Save lifedraft/bfec5a2ac752ed188b96bf5bac883acb 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: 'marketplace',
initial: 'pdp',
context: {
retries: 0
},
states: {
pdp: {
type: 'atomic',
on: {
ADD_TO_CART: 'cart'
}
},
cart: {
id: 'cart',
on: {
PROCEED_TO_CHECKOUT: 'checkout',
}
},
checkout: {
id: 'checkout',
type: 'compound',
initial: 'billing',
states: {
billing: {
on: {
NEXT: 'summary'
}
},
summary: {
on: {
NEXT: 'placeOrder'
}
},
placeOrder: {
after: {
1000: 'pooling'
}
},
pooling: {
initial: 'wait',
states: {
wait: {
after: {
1000: 'wait'
}
},
},
on: {
POST_REDIRECT: 'psp',
REDIRECT: 'psp',
SUCCESS: 'orderSuccess',
PAYMENT_CANCELED: {
target: 'cartRestore'
},
PAYMENT_FAILED: {
target: '#cart'
},
}
},
psp: {
id: 'psp',
on: {
SUCCESS: 'pooling',
PAYMENT_CANCEL: 'pooling',
WINDOW_CLOSED: {
target: '#nirvana'
}
}
},
cartRestore: {
id: 'cartRestore',
after: {
1000: '#cart'
}
},
orderSuccess: {
id: 'orderSuccess',
type: 'final'
},
}
},
nirvana: {
id: 'nirvana',
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment