Skip to content

Instantly share code, notes, and snippets.

@DaveHudson
Last active September 11, 2020 19:23
Show Gist options
  • Save DaveHudson/e63f0e0287b77bf861e6a681b664bb43 to your computer and use it in GitHub Desktop.
Save DaveHudson/e63f0e0287b77bf861e6a681b664bb43 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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