Skip to content

Instantly share code, notes, and snippets.

@f1729
Last active May 22, 2020 13:09
Show Gist options
  • Save f1729/b3bb7963d917cadb7b68030db5a0bf50 to your computer and use it in GitHub Desktop.
Save f1729/b3bb7963d917cadb7b68030db5a0bf50 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 jobMachine = Machine({
id: 'job',
initial: 'queued',
context: {
toUpdate: {},
activityType: ''
},
states: {
queued: {
on: {
running: {
actions: ['updateValuesOnRunning'],
target: 'running'
},
complete: 'complete',
"*": {
actions: ['nn']
}
}
},
running: {
on: {
complete: 'complete',
queued: 'queued'
}
},
complete: {
initial: 'complete',
entry: ['updateValuesOnComplete'],
states: {
complete: {
on: {
success: 'success',
failed: 'failed',
cancelled: 'cancelled',
'*': {
actions: ['nn']
}
}
},
success: {
entry: ['updateValuesOnComplete'],
type: 'final'
},
cancelled: {
entry: ['updateValuesOnComplete'],
type: 'final'
},
failed: {
entry: ['updateValuesOnComplete'],
type: 'final'
}
}
}
}
}, {
actions: {
nn: () => {
console.log('eeeee');
throw new Error('EEEEEEEEERROR')
},
updateValuesOnRunning: assign(() => ({
toUpdate: {
startedAt: new Date()
},
activityType: 'ACTIVITY_LOG_TYPES.JOB_START'
})),
updateValuesOnComplete: assign(() => ({
toUpdate: {
completedAt: new Date(),
completionStatus: 'oeu'
},
activityType: 'ACTIVITY_LOG_TYPES.JOB_END'
}))
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment