Skip to content

Instantly share code, notes, and snippets.

@TimeBandit
Created January 19, 2021 10:52
Show Gist options
  • Save TimeBandit/0fbe4f9834eeb9512406cfc92633d9f2 to your computer and use it in GitHub Desktop.
Save TimeBandit/0fbe4f9834eeb9512406cfc92633d9f2 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(
{
id: 'workstationId',
initial: 'start',
context: {
responseStatus: '',
},
states: {
start: {
on: {
CONNECTING: {
target: 'connection',
actions: ['connecting'],
},
},
},
connection: {
on: {
CONNECTED: {
target: 'request',
},
TIME_OUT: {
type: 'final',
actions: ['cancelled'],
},
},
},
request: {
on: {
PENDING: {
target: 'response',
actions: ['pending'],
},
},
},
response: {
on: {
SUCCESS: {
type: 'final',
actions: ['success'],
},
ABORTED: {
type: 'final',
actions: ['cancelled'],
},
FAILURE: {
type: 'final',
actions: ['cancelled'],
},
DEVICE_UNAVAILABLE: {
type: 'final',
actions: ['cancelled'],
},
BUSY: {
type: 'final',
actions: ['cancelled'],
},
LOGGED_OUT: {
type: 'final',
actions: ['cancelled'],
},
TIMED_OUT: {
type: 'final',
actions: ['cancelled'],
},
FORMAT_ERROR: {
type: 'final',
actions: ['cancelled'],
},
PARSING_ERROR: {
type: 'final',
actions: ['cancelled'],
},
COMMUNICATION_ERROR: {
type: 'final',
actions: ['cancelled'],
},
VALIDATION_ERROR: {
type: 'final',
actions: ['cancelled'],
},
MISSING_MANDATORY_DATA: {
type: 'final',
actions: ['cancelled'],
},
UNKNOWN_CARD: {
type: 'final',
actions: ['cancelled'],
},
UNKNOWN: {
type: 'final',
actions: ['unknown'],
},
},
},
},
},
{
actions: {
connecting: assign({
responseStatus: 'CONNECTING',
}),
pending: assign({
responseStatus: 'PENDING',
}),
success: assign({
responseStatus: 'SUCCESS',
pedId: (context, event) => event.value.pedId,
approvalCode: (context, event) => event.value.approvalCode,
}),
cancelled: assign({
responseStatus: 'CANCELLED',
}),
unknown: assign({
responseStatus: 'UNKNOWN',
}),
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment