Last active
October 6, 2020 14:14
-
-
Save kuroski/a76f1b7c211550d383933d530c3eea5d 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
function uploadMovie(_context, fileList) { | |
return Promise.resolve('HELLO WORLD') | |
} | |
const fetchMachine = Machine({ | |
id: "gif", | |
type: "parallel", | |
states: { | |
upload: { | |
id: "upload", | |
initial: "idle", | |
context: { | |
file: null | |
}, | |
states: { | |
idle: {}, | |
uploading: { | |
entry: assign(() => ({ | |
file: null | |
})), | |
invoke: { | |
id: "upload-file", | |
src: uploadMovie, | |
onDone: { | |
target: "uploaded", | |
actions: assign((_context, { data }) => ({ | |
file: data | |
})) | |
}, | |
onError: "failure" | |
} | |
}, | |
uploaded: { | |
on: { | |
REFRESH: "uploading", | |
RESET: "idle" | |
} | |
}, | |
failure: { | |
on: { | |
RETRY: "uploading", | |
CANCEL: "idle" | |
} | |
} | |
} | |
}, | |
drag: { | |
id: "drag", | |
initial: "idle", | |
states: { | |
idle: { | |
on: { | |
DRAGOVER: "dragover" | |
} | |
}, | |
dragover: { | |
on: { | |
DRAGLEAVE: "dragleave", | |
DROP: "drop" | |
} | |
}, | |
dragleave: { | |
on: { | |
DRAGOVER: "dragover", | |
DROP: "idle" | |
} | |
}, | |
drop: { | |
entry: raise("UPLOAD"), | |
on: { | |
DRAGOVER: "dragover", | |
} | |
} | |
} | |
} | |
}, | |
on: { | |
UPLOAD: { | |
target: ".upload.uploading" | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment