Last active
January 28, 2021 12:09
-
-
Save fbedussi/4b3839fde21ef81eec842bdaa568bd59 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
const teloMachine = Machine( | |
{ | |
id: 'telo', | |
initial: 'active', | |
context: { | |
appointmentType: 'new patient', | |
isRefractionistEnabled: true, | |
}, | |
states: { | |
active: { | |
initial: 'checkIsFollowUp', | |
states: { | |
hist: { | |
type: 'history', | |
}, | |
checkIsFollowUp: { | |
always: [ | |
{ target: 'intakeFormEnded', cond: 'isFirstExam' }, | |
{ target: 'selectPhoropter', cond: 'isFollowUp' }, | |
], | |
// old synthax kept only for visualizer | |
on: { | |
'': [ | |
{ target: 'intakeFormEnded', cond: 'isFirstExam' }, | |
{ target: 'selectPhoropter', cond: 'isFollowUp' }, | |
], | |
}, | |
}, | |
intakeFormEnded: { | |
on: { | |
ROOM_SELECTED: 'pretestStarted', | |
}, | |
}, | |
pretestStarted: { | |
on: { | |
END_PRETEST: 'pretestFinished', | |
WAIT: '#telo.waiting.restartFromIntakeFormEnded', | |
}, | |
entry: ['lockRoom', 'assignLocalTechnician'], | |
}, | |
pretestFinished: { | |
always: [{ target: 'selectPhoropter' }], | |
// old synthax kept only for visualizer | |
on: { | |
'': [{ target: 'selectPhoropter' }], | |
}, | |
entry: ['unlockRoom'], | |
}, | |
selectPhoropter: { | |
on: { | |
PHOROPTER_SELECTED: 'startTest', | |
}, | |
}, | |
startTest: { | |
always: [ | |
{ target: 'selectDoctorMode', cond: 'isRefractionistDisabled' }, | |
{ | |
target: 'readyForRefractionist', | |
cond: 'isRefractionistEnabled', | |
}, | |
], | |
// old synthax kept only for visualizer | |
on: { | |
'': [ | |
{ target: 'selectDoctorMode', cond: 'isRefractionistDisabled' }, | |
{ | |
target: 'readyForRefractionist', | |
cond: 'isRefractionistEnabled', | |
}, | |
], | |
}, | |
entry: ['lockRoom'], | |
}, | |
readyForRefractionist: { | |
on: { | |
REFRACTIONIST_STARTED: 'refractionistStarted', | |
WAIT: '#telo.waiting.restartFromSelectPhoropter', | |
}, | |
}, | |
refractionistStarted: { | |
on: { | |
REFRACTIONIST_ENDED: 'refractionistEnded', | |
WAIT: '#telo.waiting.restartFromSelectPhoropter', | |
}, | |
entry: ['assignRefractionist', 'lockRefractionist'], | |
}, | |
refractionistEnded: { | |
entry: ['unlockRefractionist'], | |
always: [{ target: 'selectDoctorMode' }], | |
// old synthax kept only for visualizer | |
on: { | |
'': [{ target: 'selectDoctorMode' }], | |
}, | |
}, | |
selectDoctorMode: { | |
on: { | |
DOCTOR_MODE_SELECTED: 'doctorModeSelected', | |
WAIT: '#telo.waiting.restartFromSelectPhoropter', | |
}, | |
}, | |
doctorModeSelected: { | |
on: { | |
DOCTOR_STARTED: 'doctorStarted', | |
WAIT: '#telo.waiting.restartFromSelectPhoropter', | |
}, | |
}, | |
doctorStarted: { | |
on: { | |
END_DOCTOR: '#telo.doctorEnded', | |
LENS_TRIAL_QUIT: '#telo.lensTrialQuit', | |
DOCTOR_ENDED_WITH_LENS_TRIAL: '#telo.doctorEndedWithLensTrial', | |
CLARIFY_QUIT: '#telo.clarifyQuit', | |
WAIT: '#telo.waiting.restartFromSelectPhoropter', | |
}, | |
entry: ['lockRoom', 'lockDoctor', 'assignDoctor'], | |
}, | |
}, | |
}, | |
paused: { | |
on: { | |
PLAY: '#telo.active.hist', | |
}, | |
}, | |
waiting: { | |
states: { | |
restartFromIntakeFormEnded: { | |
on: { RESUME: '#telo.active.intakeFormEnded' }, | |
}, | |
restartFromSelectPhoropter: { | |
on: { RESUME: '#telo.active.selectPhoropter' }, | |
}, | |
}, | |
entry: ['unlockRoom', 'unlockDoctor', 'unlockRefractionist'], | |
}, | |
aborted: { | |
type: 'final', | |
entry: [ | |
'unlockRoom', | |
'unlockDoctor', | |
'unlockRefractionist', | |
'setReason', | |
], | |
}, | |
doctorEnded: { | |
type: 'final', | |
entry: ['unlockRoom', 'unlockDoctor'], | |
}, | |
lensTrialQuit: { | |
type: 'final', | |
entry: ['unlockRoom', 'unlockDoctor'], | |
}, | |
doctorEndedWithLensTrial: { | |
type: 'final', | |
entry: ['unlockRoom', 'unlockDoctor'], | |
}, | |
clarifyQuit: { | |
type: 'final', | |
entry: ['unlockRoom', 'unlockDoctor'], | |
}, | |
}, | |
on: { | |
ABORT: 'aborted', | |
PAUSE: 'paused', | |
}, | |
}, | |
{ | |
guards: { | |
isFirstExam: (context, event) => { | |
return context.appointmentType !== 'folllow up' | |
}, | |
isFollowUp: (context, event) => { | |
return context.appointmentType === 'folllow up' | |
}, | |
isRefractionistDisabled: (context, event) => { | |
return !context.isRefractionistEnabled | |
}, | |
isRefractionistEnabled: (context, event) => { | |
return context.isRefractionistEnabled | |
}, | |
}, | |
actions: { | |
lockRoom: (context, event) => { | |
console.log('locking room') | |
alert('locking room') | |
console.log(context, event) | |
}, | |
unlockRoom: (context, event) => { | |
console.log('unlocking room') | |
alert('unlocking room') | |
console.log(context, event) | |
}, | |
lockDoctor: (context, event) => { | |
console.log('locking doctor') | |
alert('locking doctor') | |
console.log(context, event) | |
}, | |
unlockDoctor: (context, event) => { | |
console.log('unlocking doctor') | |
alert('unlocking doctor') | |
console.log(context, event) | |
}, | |
lockRefractionist: (context, event) => { | |
console.log('locking Refractionist') | |
alert('locking Refractionist') | |
console.log(context, event) | |
}, | |
unlockRefractionist: (context, event) => { | |
console.log('unlocking Refractionist') | |
alert('unlocking Refractionist') | |
console.log(context, event) | |
}, | |
assignLocalTechnician: (context, event) => { | |
console.log('assign LocalTechnician') | |
alert('assign LocalTechnician') | |
console.log(context, event) | |
}, | |
assignRefractionist: (context, event) => { | |
console.log('assign Refractionist') | |
alert('assign Refractionist') | |
console.log(context, event) | |
}, | |
assignDoctor: (context, event) => { | |
console.log('assign Doctor') | |
alert('assign Doctor') | |
console.log(context, event) | |
}, | |
setReason: (context, event) => { | |
console.log('setReason') | |
alert('setReason') | |
console.log(context, event) | |
}, | |
}, | |
}, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment