Skip to content

Instantly share code, notes, and snippets.

@natessilva
Last active August 5, 2020 15:34
Show Gist options
  • Save natessilva/06bc51eb3d68aa5422964e1a9f44d964 to your computer and use it in GitHub Desktop.
Save natessilva/06bc51eb3d68aa5422964e1a9f44d964 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: 'estimation',
initial: 'loadingEstimate',
context:{
eligFailed:false,
saveFailed:false,
calculatedFailed: false
},
states: {
loadingEstimate:{
on:{
ESTIMATE_LOAD_FAILURE: 'loadFailed',
ESTIMATE_LOADED_HAS_ELIG: 'idle',
ESTIMATE_LOADED_MISSING_ELIG: 'checkingElig'
}
},
loadFailed:{},
idle:{
on:{
CHANGE_ELIG_PARAMS: 'checkingElig',
CHANGE_OTHER_PARAMS: 'calculatingAllowed',
RETRY_SAVE: {
target: 'saving',
cond: ({saveFailed})=>saveFailed
},
RETRY_ELIG_CHECK: {
target: 'checkingElig',
cond: ({eligFailed})=>eligFailed
},
RETRY_CALC_ALLOWED: {
target: 'calculatingAllowed',
cond: ({calculatedFailed})=>calculatedFailed
},
}
},
checkingElig:{
on:{
CHANGE_ELIG_PARAMS: 'checkingElig',
ELIG_CHECK_SUCCESS: {
target: 'calculatingAllowed',
actions: assign({
eligFailed: ()=> false
})
},
ELIG_CHECK_FAILURE: {
target: 'saving',
actions: assign({
eligFailed: ()=> true
})
}
}
},
calculatingAllowed:{
on:{
CALCULATE_SUCCESS: {
target: 'saving',
actions: assign({
calculatedFailed: () => false
})
},
CALCULATE_FAILURE: {
target: 'saving',
actions: assign({
calculatedFailed: () => true
})
},
CHANGE_ELIG_PARAMS: 'checkingElig',
CHANGE_OTHER_PARAMS: 'calculatingAllowed',
}
},
saving:{
on:{
CHANGE_ELIG_PARAMS: 'savingWithEligibilityChanges',
CHANGE_OTHER_PARAMS: 'savingWithChanges',
SAVE_SUCCESS: {
target: 'idle',
actions: assign({
saveFailed: () => false
})
},
SAVE_FAILURE: {
target: 'idle',
actions: assign({
saveFailed: () => true
})
}
}
},
savingWithEligibilityChanges:{
on:{
SAVE_SUCCESS: 'checkingElig',
SAVE_FAILURE: 'checkingElig'
}
},
savingWithChanges:{
on:{
SAVE_SUCCESS: 'calculatingAllowed',
SAVE_FAILURE: 'calculatingAllowed'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment