Last active
September 28, 2020 14:53
-
-
Save akkys77/dae777dba62919bca493099d9aba5f1b 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 modelUploadMachine = Machine({ | |
| id: 'modelUpload', | |
| initial: 'idle', | |
| context: { | |
| retries: 0, | |
| step: "initial", | |
| modelName: "Model Name", | |
| companyName: "Company Name", | |
| projectName: "Project Name", | |
| tmpFile: undefined, | |
| modelUrn: undefined, | |
| mongoDBElementsCount: undefined | |
| }, | |
| states: { | |
| idle: { | |
| on: { | |
| UPLOADING: 'uploadingToWebBackEnd' | |
| } | |
| }, | |
| uploadingToWebBackEnd: { | |
| invoke: { | |
| // src: uploadToForge, | |
| onDone: { | |
| target: 'uploadingToForge', | |
| actions: assign({ | |
| tmpFile: (context, event) => { | |
| // console.log(event.data) | |
| // return event.data | |
| return `/tmp/${context.companyName} - ${context.projectName}/${context.modelName}` | |
| } | |
| }), | |
| message:"Uploaded to Web Back End" | |
| }, | |
| onError: { | |
| target: 'failure', | |
| actions: assign({ error: (context, event) => event.data, step: 'uploadingToWebBackEnd' }) | |
| } | |
| } | |
| }, | |
| uploadingToForge: { | |
| invoke: { | |
| src: uploadToForge, | |
| onDone: { | |
| target: 'uploadingToMongoDB', | |
| actions: assign({ | |
| modelUrn: (context,event) =>`urn::forge:${encodeURI(context.modelName)}` | |
| }) | |
| }, | |
| onError: { | |
| target: 'failure', | |
| actions: assign({ error: (context, event) => event.data }) | |
| } | |
| } | |
| }, | |
| uploadingToMongoDB: { | |
| invoke: { | |
| src: uploadToMongoDB, | |
| onDone: { | |
| target: 'success', | |
| actions: assign({ | |
| mongoDBElementsCount: (context, event) => `45312` | |
| }) | |
| }, | |
| onError: { | |
| target: 'failure', | |
| actions: assign({ error: (context, event) => event.data }) | |
| } | |
| } | |
| }, | |
| success: { | |
| type: 'final' | |
| }, | |
| failure: { | |
| on: { | |
| RETRY: { | |
| target: 'uploadingToWebBackEnd', | |
| // target: (context) => context.step, | |
| actions: assign({ | |
| retries: (context, event) => context.retries + 1 | |
| }) | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| function uploadToForge(context) { | |
| // return "urn::forge.com:Just a test" | |
| return setTimeout(context => Promise.resolve(context),1000) | |
| } | |
| function uploadToMongoDB(context) { | |
| // return Promise.resolve() | |
| return setTimeout(context => Promise.resolve(context),1000) | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment