Skip to content

Instantly share code, notes, and snippets.

@rsoares
Last active February 14, 2020 16:54
Show Gist options
  • Save rsoares/4dc7428f95c329da107488677a62548b to your computer and use it in GitHub Desktop.
Save rsoares/4dc7428f95c329da107488677a62548b 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 filesAppMachine = Machine({
id: 'filesApp',
initial: 'idle',
context: {
files: []
},
states: {
idle: {
on: {
FETCH_ATTACHMENTS: 'loading'
}
},
loading: {
on: {
SUCCESS: 'list',
ERROR: 'idle'
}
},
deleting: {
on: {
SUCCESS: 'list',
ERROR: 'list'
}
},
updating: {
on: {
SUCCESS: 'list',
ERROR: 'list'
}
},
setFiles: {
on: { MODAL_OPEN: 'uploadFiles' }
},
createAttachment: {
on: {
SUCCESS: {
target: 'list',
actions: assign({
files: (context, event) => context.files.concat('|')
})
},
ERROR: 'uploadFiles'
}
},
list: {
on: {
EMPTY: 'emptyList',
HYDRATE: 'hydratedList'
}
},
emptyList: {
on: {
SELECT_FILES: 'setFiles'
}
},
hydratedList: {
type: 'final',
on: {
SELECT_FILES: 'setFiles'
}
},
uploadFiles: {
on: {
SUCCESS: 'doneUploading',
ERROR: 'doneUploading'
}
},
doneUploading: {
on: {
ATTACH_FILES: 'createAttachment'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment