Skip to content

Instantly share code, notes, and snippets.

@mct-dev
Last active June 9, 2020 22:46
Show Gist options
  • Save mct-dev/cdc967158107e4f4f7d991255250b8ab to your computer and use it in GitHub Desktop.
Save mct-dev/cdc967158107e4f4f7d991255250b8ab 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 IdType = {
DriversLicense: 0,
Passport: 1
}
const FileUploadState = {
Default: 'default',
Loading: 'loading',
Success: 'success',
Fail: 'fail',
Disabled: 'disabled'
}
const fetchMachine = Machine({
id: 'idUploadMachine',
initial: 'idle',
context: {
idType: IdType.DriversLicense,
driversLicenseUpload: {
frontState: FileUploadState.Default,
backState: FileUploadState.Default
},
passportUpload: {
state: FileUploadState.Default
}
},
states: {
idle: {
on: {
CHANGE_TYPE: {
actions: assign({ idType: (ctx, e) => e.value })
},
UPLOADING_FRONT: {
target: 'uploading',
actions: assign({
driversLicenseUpload: (ctx, e) => ({
...ctx.driversLicenseUpload,
frontState: e.value
})
})
},
UPLOADING_BACK: {
target: 'uploading',
actions: assign({
driversLicenseUpload: (ctx, e) => ({
...ctx.driversLicenseUpload,
backState: e.value
})
})
},
UPLOADING_PASSPORT: {
target: 'uploading',
actions: assign({
passportUpload: (ctx, e) => ({
...ctx.passportUpload,
state: e.value
})
})
}
}
},
uploading: {}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment