Skip to content

Instantly share code, notes, and snippets.

@faneder
Created September 29, 2020 23:25
Show Gist options
  • Save faneder/099c7bc3dced9b3d4a1829acd7e61249 to your computer and use it in GitHub Desktop.
Save faneder/099c7bc3dced9b3d4a1829acd7e61249 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 isAllRejected = () => {}
const isAllSucceed = () => {}
const allSucceed = (event) => event.data.every(
(response) => response.status === 'fulfilled'
);
const assignCounts = () => {}
const assignErrorMessages = () => {}
const fetchMachine = Machine({
id: 'home',
initial: 'loading',
context: {
capGuardrailsWorkItemsCount: undefined,
newModelPriceWorkItemsCount: undefined,
modelPricePeerReviewWorkItemsCount: undefined,
colourLeverPeerReviewWorkItemsCount: undefined,
missingLeverWorkItemsCount: undefined,
missingLcvPriceWorkItemsCount: undefined,
overAgeCarWorkItemsCount: undefined,
nearlyNewCarWorkItemsCount: undefined,
errorMessages: undefined,
},
states: {
loading: {
invoke: {
id: 'getWorkItems',
src: () => {
return
Promise.allSettled([
getCapGuardrails(),
getNewModelPrices(),
getModelPricePeerReviewBatches(),
getColourLeverPeerReviewBatches(),
getMissingLever(),
getMissingLcvPrice(),
getOverAgeCars(),
getNearlyNewCars(),
]);
},
onDone: [
{
target: 'worklistsError',
cond: isAllRejected,
},
{
target: 'displayWorklists.default',
cond: isAllSucceed,
actions: 'assignCounts',
},
{
target: 'displayWorklists.worklistError.active',
actions: ['assignErrorMessages', 'assignCounts'],
},
],
},
},
displayWorklists: {
id: 'displayWorklists',
type: 'parallel',
states: {
default: {},
worklistError: {
initial: 'inactive',
states: {
active: {},
inactive: {},
},
},
},
},
emptyWorklists: {},
worklistsError: {},
},
},
{ actions: { assignCounts, assignErrorMessages } });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment