Created
June 13, 2020 14:41
-
-
Save bsbodden/3699a1533361bcebab7a6ca2c891d707 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const askForReasonForRemoval = (context, event) => {} | |
const askForReplacementReasonExplanation = (context, event) => {} | |
const confirmOperation = (context, event) => {} | |
const removeProductsFlow = Machine( | |
{ | |
id: 'remove-products', | |
initial: 'inactive', | |
context: { | |
operation: 'remove', | |
targetProduct: null, | |
targetProductId: null, | |
reason: null, | |
scannedTags: [], | |
products: [], | |
}, | |
states: { | |
inactive: { | |
on: { | |
START: [ | |
{ | |
target: 'replacement_reason', | |
cond: 'hasAtLeastOneProductInstalled', | |
}, | |
{ | |
target: 'no_installed_products', | |
}, | |
], | |
}, | |
entry: (context, event) => { | |
console.log('Loaded remove-products flow...'); | |
}, | |
}, | |
replacement_reason: { | |
invoke: { | |
id: 'askForReplacementReason', | |
src: askForReasonForRemoval, | |
}, | |
on: { | |
REASON_SELECTED: { | |
target: 'scan_product', | |
actions: assign({ | |
reason: (context, event) => event.data, | |
}), | |
}, | |
REASON_OTHER_SELECTED: { | |
target: 'replacement_reason_explanation', | |
}, | |
CANCEL: 'cancelled', | |
}, | |
}, | |
replacement_reason_explanation: { | |
invoke: { | |
id: 'askForReplacementReasonExplanation', | |
src: askForReplacementReasonExplanation, | |
}, | |
on: { | |
EXPLANATION_PROVIDED: { | |
target: 'scan_product', | |
actions: assign({ | |
reason: (context, event) => event.data, | |
}), | |
}, | |
CANCEL: 'replacement_reason', | |
}, | |
}, | |
scan_product: { | |
entry: ['scan'], | |
on: { | |
TAGS_SCANNED: { | |
target: 'confirm', | |
actions: assign({ | |
scannedTags: (context, event) => { | |
if (event.data) { | |
context.scannedTags = event.data; | |
} | |
return context.scannedTags; | |
}, | |
}), | |
}, | |
}, | |
}, | |
confirm: { | |
invoke: { | |
id: 'confirm', | |
src: (context, event) => confirmOperation(context, event), | |
onDone: { | |
target: 'finished', | |
}, | |
onError: { | |
target: 'cancelled', | |
}, | |
}, | |
}, | |
no_installed_products: { | |
entry: ['announce_no_products_installed'], | |
on: { | |
'': 'cancelled', | |
}, | |
}, | |
finished: { | |
type: 'final', | |
entry: ['submit_changes'], | |
}, | |
cancelled: { | |
type: 'final', | |
entry: ['go_back'], | |
}, | |
}, | |
}, | |
{ | |
actions: { | |
submit_changes: (context, event) => {}, | |
scan: (context, event) => {}, | |
go_back: (context, event) => {}, | |
announce_no_products_installed: (context, event) => {}, | |
}, | |
guards: { | |
hasAtLeastOneProductInstalled: context => | |
context.products && context.products.length > 0, | |
}, | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment