Skip to content

Instantly share code, notes, and snippets.

@adamfortuna
Created May 6, 2021 03:55
Show Gist options
  • Save adamfortuna/f2ca8313a5b4f6c4d43ecd5c8204c9e0 to your computer and use it in GitHub Desktop.
Save adamfortuna/f2ca8313a5b4f6c4d43ecd5c8204c9e0 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const uploaderMachine = Machine({
id: 'uploader',
initial: 'idle',
context: {
input: undefined,
payload: undefined,
activeImport: undefined,
message: undefined
},
states: {
idle: {
on: {
PARSE: 'parsing'
}
},
parsing: {
entry: ['parsePayload'],
on: {
REJECTED: {
target: 'rejected',
actions: ['setMessage']
},
PROCESSED: {
target: 'uploading',
actions: ['setPayload']
}
}
},
rejected: {
entry: ['resetForm'],
on: {
PARSE: 'parsing'
}
},
uploading: {
entry: ['uploadPayload'],
on: {
UPLOADED: 'waiting',
REJECTED: 'rejected'
}
},
waiting: {
entry: ['loadImport'],
on: {
ERROR: 'error',
PROCESS: 'processing'
}
},
processing: {
on: {
COMPLETE: 'completed',
ERROR: 'error'
}
},
completed: {
type: 'final'
},
error: {
type: 'final'
}
},
}, {
actions: {
setPayload: assign((ctx, event) => ({
results: event.results
})),
setMessage: assign((ctx, event) => ({
message: event.message
}))
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment