Skip to content

Instantly share code, notes, and snippets.

@saabi
Last active February 17, 2022 02:58
Show Gist options
  • Select an option

  • Save saabi/dda695e121e0365c0fd39c9668d051ff to your computer and use it in GitHub Desktop.

Select an option

Save saabi/dda695e121e0365c0fd39c9668d051ff to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: "fetchManager",
initial: "idle",
context: {
inputs: {
asapUris: [],
nextUris: [],
uris: [],
},
data: {},
groups: {
asap: [],
next: [],
rest: [],
},
loadingUris: [],
targetUris: [],
targetGroupId: null,
fileFetchers: [],
},
on: {
PRIORITY_CHANGED: {
actions: [
"setupManager",
// 'sendCancelU'
],
},
},
states: {
idle: {
on: {
GROUP_STARTED: {
actions: ["setTargetGroupId", "setTargetUris"],
cond: "shouldAdvance",
target: "groupFetching",
},
},
},
groupFetching: {
initial: "pending",
entry: ["spawnFileFetchers"],
states: {
pending: {
on: {
FILE_STARTED: {
actions: ["addToLoadingUris"],
target: "pending",
},
FILE_COMPLETED: {
actions: ["addFileToData"],
target: "updating",
},
FILE_CANCELLED: {
actions: ["sendCancel"],
target: "updating",
},
FILE_ERRORED: {
target: "updating",
},
},
},
updating: {
entry: [
"pullFromLoadingUris",
"deleteFileFetcher",
"sendGroupProgress",
],
always: [
{
target: "pending",
cond: "isGroupIncomplete",
},
{
target: "#fetchManager.idle",
cond: "isGroupComplete",
},
],
},
},
},
},
},{
actions: {
setTargetGroupId: ({internals:{targetGroupId}}) => {
// chhose between asap, next, rest & done
},
setTargetUris: () => {
},
spawnFileFetchers: ({internals:{targetUris}})=> {
// create fetching machines using `internals.targetUris`
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment