Skip to content

Instantly share code, notes, and snippets.

@NullVoxPopuli
Last active April 29, 2020 02:24
Show Gist options
  • Save NullVoxPopuli/15a3eb8b7d7c391bcce21d86a041a497 to your computer and use it in GitHub Desktop.
Save NullVoxPopuli/15a3eb8b7d7c391bcce21d86a041a497 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'login',
initial: 'waitForData',
context: {
retries: 0
},
states: {
waitForData: {
onEntry: 'restartEphemeralConnection',
on: {
// after typing it all in
SUBMIT: 'processLogin',
// after selecting a file?
UPLOAD: 'uploadFile',
// triggered by connection class
RECEIVE_OR_SYN: 'qrScanned',
}
},
qrScanned: {
on: {
IMPORT: 'importData',
CANCEL: 'waitForData',
ERROR: 'error',
},
},
uploadFile: {
invoke: {
id: 'handle-file',
src: 'handleFile',
onDone: 'importData',
onError: 'error',
}
},
importData: {
// shows progress
on: {
DONE: 'success',
ERROR: 'error',
}
},
error: {
on: { RETRY: '#login' },
},
processLogin: {
invoke: {
id: 'handle-login',
src: 'handleLogin',
onDone: 'success',
onError: 'error',
}
},
success: {
onEntry: ['teardownConnection', 'toChats'],
type: 'final',
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment