Skip to content

Instantly share code, notes, and snippets.

@diestrin
Created February 5, 2021 19:26
Show Gist options
  • Save diestrin/cd4176359f70401afb75732804abf698 to your computer and use it in GitHub Desktop.
Save diestrin/cd4176359f70401afb75732804abf698 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 fetchMachine = Machine({
context: {
},
initial: 'idle',
states: {
idle: {
on: {
CODE_VALIDATE: {
target: 'ready',
actions: ['assignCodes']
}
}
},
ready: {
initial: 'code',
states: {
code: {
invoke: {
id: 'load-code',
src: 'loadCode',
onDone: [
{
target: 'schedule',
actions: ['assignCode']
}
],
onError: {
target: 'invalid',
actions: ['codeNotFoundErr']
}
}
},
schedule: {
invoke: {
id: 'validate-schedule',
src: 'validateSchedule',
onDone: {
target: 'processing',
actions: ['scheduleValidateResponse', 'processSchedule']
},
onError: {
target: 'dispense'
}
}
},
dispense: {
invoke: {
id: 'validate-dispense',
src: 'validateDispense',
onDone: {
target: 'processing',
actions: ['dispenseValidateResponse', 'processSchedule']
},
onError: {
target: 'invalid',
actions: ['genericErr']
}
}
},
processing: {
invoke: {
src: 'invokeFlow',
onError: {
target: 'invalid',
actions: ['genericErr']
}
},
on: {
REPLY: {
target: 'valid',
actions: ['reply']
},
REPLY_ERROR: {
target: 'invalid',
actions: ['genericErr']
}
}
},
invalid: {
type: 'final',
},
valid: {
type: 'final'
}
}
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment