Skip to content

Instantly share code, notes, and snippets.

@saabi
Last active February 17, 2022 02:57
Show Gist options
  • Save saabi/5eb34e62544e02c92fcd52707d45098a to your computer and use it in GitHub Desktop.
Save saabi/5eb34e62544e02c92fcd52707d45098a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: "fileFetcher",
initial: "pending",
context: {
uri: ''
},
states: {
pending: {
on: {
CANCEL: {
target: "cancelled",
},
ERROR: {
target: "errored",
},
SUCCESS: {
target: "successful",
},
},
},
cancelled: {
type: "final",
entry: "cancelFileFetching",
},
errored: {
type: "final",
entry: "sendFileErrored",
},
successful: {
type: "final",
entry: "sendFileCompleted",
},
},
}, {
actions: {
cancelFileFetching: () => {},
sendFileComplete: ({groupMachine, uri}) => {
groupMachine.send('FILE_COMPLETE', {
uri,
data: null
})
},
sendFileError: ({groupMachine, uri}) => {
groupMachine.send('FILE_ERROR', {
uri,
error: null
})
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment