Skip to content

Instantly share code, notes, and snippets.

@filipemonteiroth
Created April 16, 2020 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipemonteiroth/435a69ed9d7f4116d4bb000e1c1118c3 to your computer and use it in GitHub Desktop.
Save filipemonteiroth/435a69ed9d7f4116d4bb000e1c1118c3 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: 'screen',
context: {
screen: null,
patientScreen: null,
showVisitHistory: false,
visitId: null,
productHistoryId: null,
txCompletionDate: null,
txCompletionFocusKey: null,
},
on: {
/**
* Use a single machine for all the app routes so that we can support
* navigating anywhere at any time. If we split this up and nest it
* in child React components, then deep navigation events from a top-level
* screen will get dropped. If you can discover a way to not drop deep nav
* events, then feel free to split up this screen config.
*/
GOTO_LOCKED: {target: '#lockScreen', actions: 'updateBrowserRoute'},
GOTO_STATUS_BOARD: {
target: '#statusBoardScreen',
actions: 'updateBrowserRoute',
},
GOTO_PATIENT: {
target: '#patientScreen',
actions: 'updateBrowserRoute',
},
GOTO_PATIENT_TX_SHEET: {
target: '#patientTxSheetScreen',
actions: 'updateBrowserRoute',
},
GOTO_PATIENT_CHART: {
target: '#patientChartScreen',
actions: 'updateBrowserRoute',
},
GOTO_PATIENT_VITAL: {
target: '#patientVitalScreen',
actions: 'updateBrowserRoute',
},
GOTO_PATIENT_INVOICE: {
target: '#patientInvoiceScreen',
actions: 'updateBrowserRoute',
},
GOTO_PATIENT_TX_COMPLETION: {
target: '#patientTxCompletionScreen',
actions: 'updateBrowserRoute',
},
GOTO_PATIENT_PRODUCT_HISTORY: {
target: '#patientProductHistoryScreen',
actions: 'updateBrowserRoute',
},
GOTO_ADMIN: {target: '#adminScreen', actions: 'updateBrowserRoute'},
// todo: implement back history
GO_BACK: undefined,
},
initial: 'everyone',
states: {
everyone: {
id: 'lockScreen',
entry: 'assignLock',
},
medical: {
initial: 'statusBoard',
states: {
statusBoard: {
id: 'statusBoardScreen',
entry: 'assignStatusBoard',
},
patient: {
id: 'patientScreen',
entry: 'assignPatient',
exit: 'unassignPatientScreen',
on: {
TOGGLE_VISIT_HISTORY: {
actions: ['toggleVisitHistory', 'updateBrowserRoute'],
},
},
initial: 'waitingForCache',
states: {
/**
* When a new visit is loaded, we were having issues with apollo cache not updating the data for
* some of the visit screen components. The easiest solution was to unmount everything when
* visits are changed from the patient switcher. The 300ms is an arbitrary value.
*/
waitingForCache: {
entry: 'assignPatientPending',
after: {
300: 'viewing',
},
},
viewing: {
initial: 'txSheet',
// todo: simplify all of this by generating it from a config
states: {
txSheet: {
id: 'patientTxSheetScreen',
entry: 'assignTxSheet',
},
chart: {
id: 'patientChartScreen',
entry: 'assignChart',
},
vital: {
id: 'patientVitalScreen',
entry: 'assignVital',
},
invoice: {
id: 'patientInvoiceScreen',
entry: 'assignInvoice',
},
productHistory: {
id: 'patientProductHistoryScreen',
entry: 'assignProductHistory',
},
txCompletion: {
id: 'patientTxCompletionScreen',
entry: 'assignTxCompletion',
},
},
},
},
},
},
},
business: {
id: 'adminScreen',
entry: 'assignAdmin',
on: {
TOGGLE_VISIT_HISTORY: {actions: 'toggleVisitHistory'},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment