Skip to content

Instantly share code, notes, and snippets.

@shreybatra
Last active February 24, 2020 12:21
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 shreybatra/0a3369bc505121cac5beb14549526437 to your computer and use it in GitHub Desktop.
Save shreybatra/0a3369bc505121cac5beb14549526437 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const parallelApis = Machine({
id: "Parallel-apis",
type: "parallel",
states: {
userInfo: {
initial: "apiCall",
states: {
apiCall: {
on: {
RESPONSE: "buildUserMap"
}
},
buildUserMap: {
type: "final"
}
}
},
patientInfo: {
initial: "apiCall",
states: {
apiCall: {
on: {
RESPONSE: "buildPatientMap"
}
},
buildPatientMap: {
type: "final"
}
}
},
breakglassInfo: {
initial: "apiCall",
states: {
apiCall: {
on: {
RESPONSE: "userList"
}
},
userList: {
type: "final"
}
}
}
}
});
const strategyMachine = Machine({
id: "Worklist-Search",
initial: "ui",
states: {
ui: {
on: {
GET_TODOS: "fetchTodosLoop"
}
},
fetchTodosLoop: {
on: {
NON_EMPTY_LIST: "referrals",
EMPTY_LIST: "sendResponse"
}
},
referrals: {
on: {
GET_SENT_REFERRALS: "getExternalInformation"
}
},
getExternalInformation: {
on: {
GET_INFO: "state1"
},
...parallelApis
},
state1: {
on: {
MISSING_INFORMATION: "logger",
ELSE: "checkBreakglass"
}
},
logger: {
on: {
LOG_INFO: "checkBreakglass"
}
},
checkBreakglass: {
on: {
ALLOWED_EMPI: "addPatient",
CAN_BREAK_GLASS: "addPatient",
CANNOT_BREAKGLASS: "maskPatient"
}
},
maskPatient: {
on: {
MASK_PATIENT: "addPatient"
}
},
addPatient: {
on: {
ADD_PATIENT_TO_RESPONSE: "checkResponseLimit"
}
},
checkResponseLimit: {
on: {
LEN_RESPONSE_LT_LIMIT: "fetchTodosLoop",
LEN_RESPONSE_GTE_LIMIT: "sendResponse"
}
},
sendResponse: {
type: "final"
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment