Last active
January 23, 2020 15:57
-
-
Save smirea/eeeec56a74e1f7bf3cc7e4d5831b30d0 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine({ | |
id: 'Product Status Pipeline', | |
initial: 'new', | |
context: { | |
isPublished: false, | |
hasImages: false, | |
hasData: false, | |
hasStoreAvailability: false, | |
hasPartner: false, | |
succeededTasks: 0, | |
imagesProcessed: false, | |
digitization: { | |
outOfStock: null, | |
needsImages: true, | |
needsDimensions: true, | |
needsVerification: false, | |
}, | |
}, | |
states: { | |
new: { | |
on: { | |
ENABLE_STORE_DIGITIZATION: { | |
target: 'digitization', | |
cond: 'readyForDigitization', | |
}, | |
SET_STORE_AVAILABILITY: { | |
actions: ['setStoreAvailability'], | |
}, | |
SET_PARTNER: { | |
actions: ['setPartner'], | |
}, | |
}, | |
}, | |
digitization: { | |
id: 'digitization', | |
initial: 'pending', | |
states: { | |
cart: { | |
on: { | |
ADD_IMAGES: { | |
actions: 'addImages', | |
cond: 'needsImages', | |
}, | |
ADD_DIMENSIONS: { | |
actions: 'addDimensions', | |
cond: 'needsDimensions', | |
}, | |
SUBMIT: { | |
target: '#ingestion', | |
cond: 'readyForIngestion', | |
}, | |
}, | |
}, | |
pending: { | |
on: { | |
ADD_TO_CART: { | |
target: 'cart', | |
actions: 'clearOutOfStock', | |
cond: 'needsImagesOrDimensions', | |
}, | |
OUT_OF_STOCK: { | |
target: 'pending', | |
actions: 'setOutOfStock', | |
cond: 'needsImagesOrDimensions', | |
}, | |
VERIFY_UP_TO_DATE: { | |
target: '#done', | |
actions: 'setVerification', | |
cond: 'needsVerification', | |
}, | |
VERIFY_NEEDS_REDO: { | |
target: 'pending', | |
actions: 'setVerification', | |
cond: 'needsVerification', | |
}, | |
}, | |
}, | |
}, | |
}, | |
ingestion: { | |
id: 'ingestion', | |
type: 'parallel', | |
on: { | |
SUBMIT: { | |
target: '#qa', | |
cond: 'readyForQa', | |
}, | |
}, | |
states: { | |
imageProcessing: { | |
id: 'imageProcessing', | |
initial: 'pending', | |
states: { | |
pending: { | |
on: { | |
'': { | |
target: 'done', | |
cond: 'allImagesProcessed', | |
}, | |
DOWNLOAD: 'processing', | |
}, | |
}, | |
processing: { | |
on: { | |
UPLOAD: { | |
target: 'done', | |
actions: 'imagesFinishedProcessing', | |
}, | |
NO_UPLOAD: 'error', | |
}, | |
}, | |
done: {}, | |
error: { | |
type: 'final', | |
}, | |
}, | |
}, | |
mturk: { | |
id: 'mturk', | |
initial: 'pending', | |
states: { | |
pending: { | |
on: { | |
CREATE_TAXONOMY_TASK: 'taxonomy', | |
}, | |
}, | |
taxonomy: { | |
on: { | |
CREATE_VALIDATION_TASK: 'runTasks', | |
}, | |
}, | |
runTasks: { | |
on: { | |
GENERATE_OTHER_TASKS: { | |
target: 'runTasks', | |
actions: 'succeedTask', | |
}, | |
ALL_TASKS_RESOLVED: { | |
target: 'done', | |
cond: 'tasksProcessedSuccessfully', | |
}, | |
TASK_FAILED: 'error', | |
}, | |
}, | |
done: {}, | |
error: { | |
type: 'final', | |
}, | |
}, | |
}, | |
}, | |
}, | |
qa: { | |
id: 'qa', | |
initial: 'pending', | |
states: { | |
pending: { | |
on: { | |
ALL_CHECKS_PASSED: '#done', | |
SOME_CHECKS_FAILED: 'error', | |
}, | |
}, | |
error: { | |
type: 'final', | |
}, | |
}, | |
}, | |
done: { | |
id: 'done', | |
initial: 'inactive', | |
states: { | |
inactive: { | |
on: { | |
'': { | |
target: 'active', | |
cond: 'isPublished', | |
}, | |
ACTIVATE: { | |
target: 'active', | |
actions: 'publish', | |
}, | |
}, | |
}, | |
active: { | |
on: { | |
DEACTIVATE: { | |
target: 'inactive', | |
actions: 'unpublish', | |
}, | |
}, | |
}, | |
}, | |
on: { | |
VERIFY: { | |
target: '#digitization', | |
actions: 'setNeedsVerification', | |
}, | |
GENERATE_MORE_TASKS: { | |
target: '#mturk.runTasks', | |
}, | |
}, | |
}, | |
}, | |
}, { | |
guards: { | |
readyForDigitization: ctx => | |
ctx.hasStoreAvailability && | |
ctx.hasPartner, | |
readyForIngestion: ctx => | |
ctx.hasImages, | |
needsImages: ctx => | |
ctx.digitization.needsImages, | |
needsDimensions: ctx => | |
ctx.digitization.needsDimensions, | |
needsImagesOrDimensions: ctx => | |
ctx.digitization.needsImages || | |
ctx.digitization.needsDimensions, | |
needsVerification: ctx => | |
ctx.digitization.needsVerification, | |
tasksProcessedSuccessfully: ctx => | |
ctx.succeededTasks >= 3, | |
readyForQa: ctx => | |
ctx.succeededTasks >= 3 && ctx.imagesProcessed, | |
allImagesProcessed: ctx => | |
ctx.imagesProcessed, | |
isPublished: ctx => | |
ctx.isPublished, | |
}, | |
actions: { | |
setStoreAvailability: assign({ | |
hasStoreAvailability: true, | |
}), | |
setPartner: assign({ | |
hasPartner: true, | |
}), | |
addImages: assign({ | |
hasImages: true, | |
digitization: ctx => ({ | |
...ctx.digitization, | |
needsImages: false, | |
}), | |
}), | |
addDimensions: assign({ | |
hasDimensions: true, | |
digitization: ctx => ({ | |
...ctx.digitization, | |
needsDimensions: false, | |
}), | |
}), | |
setOutOfStock: assign({ | |
digitization: ctx => ({ | |
...ctx.digitization, | |
outOfStock: (new Date).toISOString(), | |
}), | |
}), | |
clearOutOfStock: assign({ | |
digitization: ctx => ({ | |
...ctx.digitization, | |
outOfStock: null, | |
}), | |
}), | |
setNeedsVerification: assign({ | |
digitization: (ctx, { type }) => ({ | |
...ctx.digitization, | |
needsVerification: true, | |
}), | |
}), | |
setVerification: assign({ | |
digitization: (ctx, { type }) => ({ | |
...ctx.digitization, | |
needsVerification: false, | |
...(type !== 'VERIFY_NEEDS_REDO' ? null : { | |
needsImages: true, | |
needsDimensions: true, | |
}), | |
}), | |
}), | |
succeedTask: assign({ | |
succeededTasks: ctx => ctx.succeededTasks + 1, | |
}), | |
publish: assign({ | |
isPublished: true, | |
}), | |
unpublish: assign({ | |
isPublished: false, | |
}), | |
imagesFinishedProcessing: assign({ | |
imagesProcessed: true, | |
}), | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment