Skip to content

Instantly share code, notes, and snippets.

@tmbtech
Last active July 28, 2021 07:34
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 tmbtech/59fee9e84e2f8bab21a526a0cc08da1a to your computer and use it in GitHub Desktop.
Save tmbtech/59fee9e84e2f8bab21a526a0cc08da1a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine(
{
id: 'isi-builder',
initial: 'start',
context: {
brands: ['botox', 'kybella'],
},
states: {
start: {
on: {
'': [
{ target: 'containsBotox', cond: 'containsBotox' },
{
target: 'singleSafetyAndPrescribingInfo',
cond: 'hasKybellaOrLatisse',
},
{ target: 'importantSafetyInformationOnly' },
],
},
},
containsBotox: {
on: {
'': [
{ target: 'botoxOnly', cond: 'hasOnlyOneCondition' },
{
target: 'botoxSafetyAndPrescribingInfo',
cond: 'hasKybellaOrLatisse',
},
{ target: 'botoxOnlyImportantSafetyInformationOnly' },
],
},
},
singleSafetyAndPrescribingInfo: {},
importantSafetyInformationOnly: {},
doesNotContainBotox: {},
hasOnlyOneCondition: {},
botoxOnly: {},
botoxSafetyAndPrescribingInfo: {},
botoxOnlyImportantSafetyInformationOnly:{}
},
},
{
guards: {
doesNotContainBotox: (context) => {
return !context.brands.includes('botox');
},
containsBotox: (context) => {
return context.brands.includes('botox');
},
hasOnlyOneCondition: (context) => {
return context.brands.length === 1;
},
hasKybellaOrLatisse: (context) => {
return context.brands.some(
(brand) => brand === 'kybella' || brand === 'latisse'
);
},
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment