Last active
August 16, 2020 20:04
-
-
Save Masquerade-Circus/93563622402ac502183e8dcc7386425c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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) | |
let fetchMachine = Machine({ | |
id: "order", | |
initial: "unknown", | |
context: { | |
state: '' | |
}, | |
states: { | |
unknown: { | |
on: { | |
create: 'created', | |
draft: 'draft' | |
} | |
}, | |
draft: { | |
entry: ['getClient', 'getItemsAndTaxes', 'getAmounts', 'draft'], | |
on: { | |
expireDraft: 'expiredDraft' | |
} | |
}, | |
expiredDraft: { | |
entry: ['getClient', 'expireDraft'], | |
type: 'final' | |
}, | |
created: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'validatePickupTime', | |
'getItemsAndTaxes', | |
'getAmounts', | |
'getCard', | |
'create', | |
'authorize' | |
], | |
on: { | |
expire: 'expired', | |
authFail: 'authorizationFailure', | |
authSuccess: 'authorizationSuccess' | |
} | |
}, | |
authorizationFailure: { | |
entry: [ | |
'setError', | |
'createTransaction', | |
'update', | |
'sendNotificationToClient', | |
'throwError' | |
], | |
type: 'final' | |
}, | |
authorizationSuccess: { | |
entry: ['createTransaction', 'update'], | |
on: { | |
expire: 'expired', | |
waiting: 'waitingForStore' | |
} | |
}, | |
waitingForStore: { | |
entry: ['sendNotificationToClient', 'setTimeoutTasks', 'update'], | |
on: { | |
expire: 'expired', | |
cancel: 'cancelledByStore', | |
cancelByClient: 'cancelledByClient', | |
requestChanges: 'changesRequestedByStore', | |
process: 'processing', | |
cancelByCustomerSupport: 'cancelledByCustomerSupport', | |
voidFail: 'voidFailure' | |
} | |
}, | |
cancelledByClient: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'getCard', | |
'getItemsAndTaxes', | |
'getTransaction', | |
'voidOrRefundOrder', | |
'update', | |
'updateTransaction', | |
'sendNotificationToStore', | |
'sendNotificationToClient' | |
], | |
type: 'final' | |
}, | |
cancelledByStore: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'getCard', | |
'getItemsAndTaxes', | |
'getTransaction', | |
'voidOrRefundOrder', | |
'update', | |
'updateTransaction', | |
'sendNotificationToClient' | |
], | |
type: 'final' | |
}, | |
expired: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'getCard', | |
'getItemsAndTaxes', | |
'expire', | |
'getTransaction', | |
'voidOrRefundOrder', | |
'update', | |
'updateTransaction', | |
'sendNotificationToClient' | |
], | |
type: 'final' | |
}, | |
changesRequestedByStore: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'getCard', | |
'getItemsAndTaxes', | |
'getAmounts', | |
'update', | |
'sendNotificationToClient' | |
], | |
on: { | |
rejectChanges: 'changesRejectedByClient', | |
acceptChanges: 'changesAcceptedByClient', | |
cancelByCustomerSupport: 'cancelledByCustomerSupport', | |
voidFail: 'voidFailure' | |
} | |
}, | |
changesRejectedByClient: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'getCard', | |
'getItemsAndTaxes', | |
'getTransaction', | |
'voidOrRefundOrder', | |
'update', | |
'updateTransaction', | |
'sendNotificationToStore', | |
'sendNotificationToClient' | |
], | |
type: 'final' | |
}, | |
changesAcceptedByClient: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'getCard', | |
'getItemsAndTaxes', | |
'update', | |
'sendNotificationToStore' | |
], | |
on: { | |
process: 'processing', | |
cancel: 'cancelledByStore', | |
cancelByCustomerSupport: 'cancelledByCustomerSupport', | |
voidFail: 'voidFailure' | |
} | |
}, | |
processing: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'getCard', | |
'getItemsAndTaxes', | |
'update', | |
'sendNotificationToClient' | |
], | |
on: { | |
cancelProcessing: 'processingCancelledByStore', | |
finishProcessing: 'processed', | |
cancelByCustomerSupport: 'cancelledByCustomerSupport', | |
voidFail: 'voidFailure' | |
} | |
}, | |
processingCancelledByStore: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'getCard', | |
'getItemsAndTaxes', | |
'getTransaction', | |
'voidOrRefundOrder', | |
'update', | |
'updateTransaction', | |
'sendNotificationToClient' | |
], | |
type: 'final' | |
}, | |
processed: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'getCard', | |
'getItemsAndTaxes', | |
'getTransaction', | |
'update', | |
'capture' | |
], | |
on: { | |
captureFail: 'captureFailure', | |
captureSuccess: 'captureSuccess' | |
} | |
}, | |
captureFailure: { | |
entry: [ | |
'setError', | |
'voidOrRefundOrder', | |
'update', | |
'updateTransaction', | |
'sendNotificationToClient', | |
'sendNotificationToStore', | |
'throwError' | |
], | |
type: 'final' | |
}, | |
captureSuccess: { | |
entry: ['update', 'updateTransaction'], | |
on: { ready: 'ready' } | |
}, | |
ready: { | |
entry: ['update', 'sendNotificationToClient'], | |
on: { | |
complete: 'completed', | |
cancelReady: 'readyCancelledByStore', | |
cancelByCustomerSupport: 'cancelledByCustomerSupport', | |
refundFail: 'refundFailure' | |
} | |
}, | |
readyCancelledByStore: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'getCard', | |
'getItemsAndTaxes', | |
'getTransaction', | |
'voidOrRefundOrder', | |
'update', | |
'updateTransaction', | |
'sendNotificationToClient' | |
], | |
type: 'final' | |
}, | |
completed: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'getCard', | |
'update' | |
], | |
on: { | |
cancelCompleted: 'completedCancelledByStore', | |
cancelByCustomerSupport: 'cancelledByCustomerSupport', | |
refundFail: 'refundFailure' | |
} | |
}, | |
completedCancelledByStore: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'getCard', | |
'getItemsAndTaxes', | |
'getTransaction', | |
'voidOrRefundOrder', | |
'update', | |
'updateTransaction', | |
'sendNotificationToClient' | |
], | |
type: 'final' | |
}, | |
cancelledByCustomerSupport: { | |
entry: [ | |
'getClient', | |
'getStore', | |
'getRetailer', | |
'setI18N', | |
'getCard', | |
'getItemsAndTaxes', | |
'getTransaction', | |
'setCancelledById', | |
'voidOrRefundOrder', | |
'update', | |
'updateTransaction', | |
'sendNotificationToClient' | |
], | |
type: 'final' | |
}, | |
refundFailure: { | |
entry: ['setError', 'updateTransaction', 'update', 'throwError'], | |
type: 'final' | |
}, | |
voidFailure: { | |
entry: ['setError', 'updateTransaction', 'update', 'throwError'], | |
type: 'final' | |
} | |
} | |
}, { | |
actions: { | |
setErrors: () => console.log('Setting errors in context'), | |
find: () => console.log('Find order by id'), | |
save: (context, event, meta, data) => { | |
console.log(context, event, meta, data) | |
context.state = meta.state.value; | |
console.log('Saving', context); | |
}, | |
authorize: () => { | |
console.log('Authorizing...'); | |
console.log('After authorizing result we send the resulted event AUTH_FAIL or AUTH_SUCCESS'); | |
}, | |
capture: () => console.log('Capturing...'), | |
sendNotificationToStore: () => console.log('Sending notification to store...'), | |
sendNotificationToClient: () => console.log('Sending notification to client...'), | |
sendAlert: () => console.log('Send alert...'), | |
expire:() => console.log('Expiring order'), | |
voidOrder: () => console.log('Void payment...') | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment