Skip to content

Instantly share code, notes, and snippets.

@lifedraft
Last active March 3, 2020 13:58
Show Gist options
  • Save lifedraft/354a871ac5328bff6be779e8c59d3de9 to your computer and use it in GitHub Desktop.
Save lifedraft/354a871ac5328bff6be779e8c59d3de9 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({
initial: 'pdp',
context: {},
states: {
pdp: {
entry: ['enableForm'],
on: {
START: {
target: 'cartCheck',
actions: ['disableForm']
}
}
},
cartCheck: {
entry: ['setLoading'],
on: {
PROCEED: 'addProductToCart',
ERROR_EVALUATE: 'errorEvaluate',
HTTP_ERROR: 'error'
}
},
addProductToCart: {
entry: ['setLoading'],
on: {
SUCCESS: 'success',
FAIL: 'errorEvaluate'
},
},
errorEvaluate: {
on: {
FLIGHT_REQUIRED: 'flightModal',
KNOWN_ERROR: 'error',
UNKOWN_ERROR: 'error'
}
},
flightModal: {
on: {
SUCCESS: {
target: 'pdp',
actions: ['resetForm'],
},
CANCEL: 'pdp'
}
},
success: {
on: {
COMPLETE: {
target: 'pdp',
actions: ['resetForm']
}
},
},
error: {
on: {
COMPLETE: 'pdp'
}
}
},
actions: {
disableForm: () => console.log('disableForm'),
enableForm: () => console.log('enableForm'),
resetForm: () => console.log('resetForm'),
setLoading: () => console.log('setLoading'),
setLoading: () => console.log('setLoading')
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment