Created
April 27, 2020 14:39
-
-
Save mstruebing/d5c462b1c176dd3ec2c32823dde67bde 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 careplanMachine = Machine( | |
{ | |
id: "careplan", | |
key: "careplan", | |
initial: "onboarding", | |
states: { | |
onboarding: { | |
on: { | |
REDUCE_WEIGHT: "reduce_weight", | |
SLEEP_ENHANCEMENT: "sleep_enhancement" | |
} | |
}, | |
reduce_weight: { | |
id: "reduce_weight", | |
key: "reduce_weight", | |
type: "parallel", | |
states: { | |
recipe: { | |
id: "recipe", | |
key: "recipe", | |
initial: "show_recipe", | |
states: { | |
show_recipe: { | |
entry: ["refresh"], | |
meta: { | |
refresh_hour: "8" | |
}, | |
on: { | |
REFRESH: "show_recipe" | |
} | |
} | |
} | |
}, | |
blood_sugar_survey: { | |
id: "blood_sugar_survey", | |
key: "blood_sugar_survey", | |
initial: "input", | |
states: { | |
input: { | |
on: { | |
OVER_500: "over_500", | |
UNDER_500: "under_500" | |
} | |
// needs action to notify in 2 days | |
}, | |
over_500: { | |
meta: { | |
content: "Call a doctor!" | |
}, | |
on: { | |
DONE: "wait_for_next_day" | |
} | |
}, | |
under_500: { | |
meta: { | |
content: "Bloodsugar information" | |
}, | |
on: { | |
DONE: "wait_for_next_day" | |
} | |
}, | |
wait_for_next_day: { | |
entry: ["repeat"], | |
meta: { | |
interval: "daily" | |
}, | |
on: { | |
WAITED: "input" | |
} | |
} | |
} | |
}, | |
research: { | |
initial: "show_video", | |
states: { | |
show_video: { | |
type: "final", | |
meta: { | |
content: "videourl" | |
} | |
} | |
} | |
} | |
} | |
}, | |
sleep_enhancement: { | |
id: "sleep_enhancement", | |
key: "sleep_enhancement", | |
type: "parallel", | |
states: { | |
content: { | |
initial: "show_content", | |
states: { | |
show_content: { | |
entry: ["notify", "refresh"], | |
exit: ["cancel_notify"], | |
meta: { | |
notify_hour: "22", | |
refresh_hour: "20", | |
// needs some meta data to choose from contents | |
}, | |
on: { | |
REFRESH: "refresh" | |
} | |
}, | |
refresh: { | |
on: { | |
"": "show_content" | |
} | |
} | |
} | |
}, | |
blood_sugar_survey: { | |
id: "blood_sugar_survey", | |
key: "blood_sugar_survey", | |
initial: "input", | |
states: { | |
input: { | |
on: { | |
OVER_500: "over_500", | |
UNDER_500: "under_500" | |
} | |
// needs action to notify in 2 days | |
}, | |
over_500: { | |
meta: { | |
content: "Call a doctor!" | |
}, | |
on: { | |
DONE: "wait_for_next_day" | |
} | |
}, | |
under_500: { | |
meta: { | |
content: "Bloodsugar information" | |
}, | |
on: { | |
DONE: "wait_for_next_day" | |
} | |
}, | |
wait_for_next_day: { | |
entry: ["repeat"], | |
meta: { | |
interval: "daily" | |
}, | |
on: { | |
WAITED: "input" | |
} | |
} | |
} | |
}, | |
wellbeing_survey: { | |
id: "wellbeing_survey", | |
key: "wellbeing_survey", | |
initial: "how_are_you", | |
states: { | |
how_are_you: { | |
on: { | |
GOOD: "good", | |
bad: "bad" | |
} | |
// needs action to notify in 2 weeks | |
}, | |
good: { | |
type: "final", | |
meta: { | |
content: "Great, you are healthy" | |
} | |
}, | |
bad: { | |
on: { | |
FEET: "feet", | |
HEAD: "head" | |
} | |
}, | |
feet: { | |
on: { | |
PAIN: "pain", | |
NO_PAIN: "no_pain" | |
} | |
}, | |
head: { | |
on: { | |
PAIN: "pain", | |
NO_PAIN: "no_pain" | |
} | |
}, | |
pain: { | |
type: "final", | |
meta: { | |
content: "Call a doctor" | |
} | |
}, | |
no_pain: { | |
type: "final", | |
meta: { | |
content: "Not so bad" | |
} | |
} | |
} | |
// action to repeat every week | |
// after 2 weeks: sms | |
} | |
} | |
} | |
} | |
}, | |
{ | |
actions: { | |
notify: (context, user_id) => { | |
// maybe a crontab string? | |
const when = Object.values(context.meta)[0].notify_hour; | |
console.log(`INVOKE SERVICE TO NOTIFY AT ${when} O'CLOCK`); | |
}, | |
refresh: (context, user_id) => { | |
// maybe a crontab string? | |
const when = Object.values(context.meta)[0].refresh_hour; | |
console.log(`INVOKE SERVICE TO REFRESH AT ${when} O'CLOCK`); | |
}, | |
cancel_notify: (context, user_id) => { | |
console.log("INVOKE SERVICE TO CANCEL THE FORMER NOTIFICATION"); | |
}, | |
repeat: (context, user_id) => { | |
// maybe a crontab string? | |
const interval = Object.values(context.meta)[0].interval; | |
console.log(`INVOKE SERVICE TO REPEAT ${interval}`); | |
} | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment