Last active
April 8, 2021 17:59
-
-
Save dsathyakumar/42a57395396e98d10c41b91b16c25cfa 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 UploaderMachine = Machine( | |
{ | |
strict: true, | |
id: "uploader-machine", | |
context: { | |
progress: false, | |
progressDataModel: { | |
progressMsg: "", | |
infoMsg: "", | |
progressPercent: "", | |
retryCount: 0, | |
maxRetries: 3, | |
}, | |
}, | |
initial: "idle", | |
states: { | |
idle: { | |
type: "atomic", | |
on: { | |
VALIDATE: { | |
target: "validate", | |
}, | |
POLL: { | |
target: "poll", | |
}, | |
}, | |
}, | |
validate: { | |
type: "atomic", | |
on: { | |
"": [{ target: "upload", cond: "isValid" }, { target: "idle" }], | |
}, | |
}, | |
upload: { | |
type: "compound", | |
initial: "trigger", | |
states: { | |
trigger: {}, | |
start: { | |
on: { | |
UPLOAD_ERROR: { | |
target: "error", | |
}, | |
UPLOAD_TIMEOUT: { | |
target: "timeout", | |
}, | |
UPLOAD_PROGRESS: { | |
target: "progress", | |
}, | |
}, | |
}, | |
progress: { | |
on: { | |
UPLOAD_SUCCESS: { | |
target: "success", | |
}, | |
UPLOAD_ERROR: { | |
target: "error", | |
}, | |
UPLOAD_TIMEOUT: { | |
target: "timeout", | |
}, | |
UPLOAD_PROGRESS: {}, | |
}, | |
}, | |
success: { | |
on: { | |
POLL_START: { | |
target: "#uploader-machine.poll", | |
}, | |
}, | |
}, | |
error: { | |
on: { | |
"": [ | |
{ target: "trigger", cond: "shouldRetryUpload" }, | |
{ target: "#uploader-machine.idle" }, | |
], | |
}, | |
}, | |
timeout: { | |
on: { | |
"": [ | |
{ target: "trigger", cond: "shouldRetryUpload" }, | |
{ target: "#uploader-machine.idle" }, | |
], | |
}, | |
}, | |
}, | |
}, | |
poll: { | |
type: "compound", | |
initial: "trigger", | |
states: { | |
trigger: {}, | |
success: {}, | |
error: { | |
on: { | |
"": [ | |
{ target: "trigger", cond: "shouldRetryPoll" }, | |
{ target: "#uploader-machine.idle" }, | |
], | |
}, | |
}, | |
timeout: { | |
on: { | |
"": [ | |
{ target: "trigger", cond: "shouldRetryPoll" }, | |
{ target: "#uploader-machine.idle" }, | |
], | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
{ | |
actions: {}, | |
guards: { | |
isValid: (ctx, evt) => {}, | |
shouldRetryUpload: (ctx, evt) => {}, | |
shouldRetryUpload: (ctx, evt) => {}, | |
}, | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment