Skip to content

Instantly share code, notes, and snippets.

@christianjuth
Last active March 18, 2021 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianjuth/42dd751e28b66a01538741a67b60c3f0 to your computer and use it in GitHub Desktop.
Save christianjuth/42dd751e28b66a01538741a67b60c3f0 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: 'checkout',
initial: 'cartLoading',
context: {
cart: {},
error: ''
},
states: {
cartLoading: {
on: {
CARD_LOADED: 'dataEntry',
CART_LOADING_FAILED: 'cartLoadingFailed'
}
},
cartLoadingFailed: {
type: 'final'
},
dataEntry: {
on: {
KEYBOARD_INPUT: 'dataEntry',
ADD_PROMO_CODE: 'promoCodeFetching',
ADD_CARD: 'cardAdding',
SUBMIT: 'submitting'
}
},
error: {
on: {
KEYBOARD_INPUT: 'dataEntry',
ADD_PROMO_CODE: 'promoCodeFetching',
ADD_CARD: 'cardAdding'
}
},
promoCodeFetching: {
on: {
PROMO_CODE_SUCCESS: 'dataEntry',
PROMO_CODE_FAILURE: 'error'
}
},
cardAdding: {
on: {
CARD_ADDING_SUCCESS: 'dataEntry',
CARD_ADDING_FAILURE: 'error'
}
},
submitting: {
on: {
SUBMITTING_SUCCESS: 'done',
SUBMITTING_ERROR: 'error'
}
},
done: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment