Skip to content

Instantly share code, notes, and snippets.

@erikras
Last active January 23, 2021 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikras/f9d320c73af7cbd67c1d3295caca6960 to your computer and use it in GitHub Desktop.
Save erikras/f9d320c73af7cbd67c1d3295caca6960 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const jobsMachine = Machine({
id: 'jobs',
initial: 'loading',
context: {},
states: {
loading: {
invoke: {
id: 'loadJobs',
onDone: { target: 'idle', actions: 'writeDataToContext' },
},
},
idle: {
on: {
OPEN_DELETE_JOB_DIALOG: {
target: 'deleteJobDialog',
actions: 'writeJobIdToContext',
},
OPEN_CREATE_JOB_DIALOG: {
target: 'createJobDialog',
actions: 'writeEmptyVariablesToContext',
},
OPEN_EDIT_JOB_DIALOG: {
target: 'editJobDialog',
actions: ['writeJobIdToContext', 'writeVariablesToContext'],
},
OPEN_DUPLICATE_JOB_DIALOG: {
target: 'createJobDialog',
actions: ['writeVariablesToContext'],
},
},
},
deleteJobDialog: {
on: {
DELETE_JOB: 'deleting',
CANCEL: { target: 'idle', actions: 'clearContext' },
},
},
deleting: {
invoke: {
id: 'deleteJob',
onDone: 'idle',
},
entry: 'removeJobFromContext',
exit: 'removeJobIdFromContext',
},
createJobDialog: {
on: {
CANCEL: { target: 'idle', actions: 'clearContext' },
CREATE_JOB: {
target: 'creatingJob',
actions: 'writeVariablesToContext',
},
},
},
creatingJob: {
invoke: {
id: 'createJob',
onDone: { target: 'idle', actions: 'appendJob' },
},
},
editJobDialog: {
on: {
CANCEL: { target: 'idle', actions: 'clearContext' },
OPEN_DELETE_JOB_DIALOG: 'deleteJobDialog',
UPDATE_JOB: {
target: 'updatingJob',
actions: ['writeVariablesToContext', 'optimisticallyUpdateJob'],
},
},
},
updatingJob: {
invoke: {
id: 'updateJob',
onDone: 'idle',
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment