Last active
September 11, 2020 19:23
-
-
Save DaveHudson/e63f0e0287b77bf861e6a681b664bb43 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 uploadImageMachine = Machine({ | |
id: 'uploadImage', | |
initial: 'idle', | |
context: { | |
data: undefined, | |
error: undefined, | |
}, | |
states: { | |
idle: { | |
on: { | |
CHANGE: { | |
target: "uploadToS3", | |
actions: [] | |
}, | |
CANCEL: { | |
target: "deleteS3Image" | |
}, | |
SUBMIT: [ | |
{ | |
target: "saveToDynamo", | |
cond: "hasS3Key" | |
}, | |
{ | |
target: "error" | |
} | |
] | |
}, | |
}, | |
uploadToS3: { | |
invoke: { | |
src: "uploadService", | |
onDone: { | |
target: "idle", | |
actions: ["setS3State"] | |
}, | |
onError: { | |
target: "error", | |
actions: ["setError"] | |
} | |
} | |
}, | |
saveToDynamo: { | |
invoke: { | |
src: "createImageAPI", | |
onDone: { | |
target: "success" | |
}, | |
onError: { | |
target: "error", | |
actions: ["setError"] | |
} | |
} | |
}, | |
deleteS3Image: { | |
invoke: { | |
src: "deleteImageAPI", | |
onDone: { | |
target: "success", | |
}, | |
onError: { | |
target: "error", | |
actions: ["setError"] | |
} | |
} | |
}, | |
success: { | |
type: 'final' | |
}, | |
error: {} | |
} | |
},{ | |
guards: { | |
hasS3Key: (context) => { | |
return true; | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment