Last active
May 22, 2020 13:09
-
-
Save f1729/b3bb7963d917cadb7b68030db5a0bf50 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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