Skip to content

Instantly share code, notes, and snippets.

@11111000000
Last active October 28, 2019 19:23
Show Gist options
  • Save 11111000000/c8e5a89f6d7d9e28fe328c30338f640a to your computer and use it in GitHub Desktop.
Save 11111000000/c8e5a89f6d7d9e28fe328c30338f640a 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: 'sliza',
initial: 'closed',
context: {
auth: true,
error: false,
attributes: {
'site_mlm': false
}
},
states: {
closed: {
on: {
OPEN: [
{ cond: (context, event) => (context.error == 'siteNotInCatalogue'), target: 'site_not_in_catalogue' },
{ cond: (context, event) => (context.error == 'siteNotPayed'), target: 'site_not_payed' },
{ cond: (context, event) => (!context.auth), target: 'auth' },
{ cond: (context, event) => (context.attributes.teaser), target: 'teaser' },
{ cond: (context, event) => (context.attributes.site_mlm), target: 'show_mlm' },
{ cond: (context, event) => (context.type == 'pro'), target: 'show_pro' },
{ cond: (context, event) => (context.type == 'none'), target: 'show_soon' },
{ cond: (context, event) => true, target: 'show_start' }
]
}
},
auth: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
'SLIZA.AUTH.COMPLETE': {target: 'show_start', actions: 'authorized'},
'SLIZA.AUTH.FAIL': 'auth'
}
},
auth_failed: {
},
site_unknown: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed'
}
},
site_not_in_catalogue: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed'
}
},
teaser: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
'SLIZA.WIDGET.APPLY': 'onboarding'
}
},
no_goods: {
on: {
'SLIZA.WIDGET.CLOSE' :'closed',
'SLIZA.WIDGET.RESTART': 'show_start'
}
},
onboarding: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
'SLIZA.WIDGET.APPLY': 'show_start'
}
},
site_under_development: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed'
}
},
template_not_payed: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed'
}
},
show_pro: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
'SLIZA.WIDGET.PRO_SHOWN': 'show_start'
}
},
show_mlm: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
'SLIZA.WIDGET.MLM_SHOWN': 'show_start'
}
},
show_soon: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
'SLIZA.WIDGET.APPLY': 'onboarding'
}
},
show_start: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
'SLIZA.WIDGET.STEP1.START': 'start_loading'
}
},
start_loading: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
'SLIZA.WIDGET.LOADING.FINISHED': 'step2',
'SLIZA.WIDGET.LOADING.FAILED': 'loading_error'
}
},
loading_error: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
}
},
step2: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
'SLIZA.WIDGET.STEP2.START': 'step3',
'SLIZA.WIDGET.STEP2.NO_PRODUCTS': 'step2_no_products',
'SLIZA.TECH_ERROR': [{cond: (context => !!context.debug), target: 'tech_error_with_debug'},
{cond: (context => !context.debug), target: 'tech_error'}]
}
},
step2_no_products: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
'SLIZA.WIDGET.BACK_TO_STEP2': 'step2'
}
},
step3: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
'SLIZA.WIDGET.STEP3.SAVE': 'save_upload'
}
},
tech_error: {
'SLIZA.WIDGET.CLOSE': 'closed'
},
tech_error_with_debug: {
'SLIZA.WIDGET.CLOSE': 'closed'
},
// step2_no_products: {
// 'SLIZA.WIDGET.CLOSE': 'closed'
// },
save_upload: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
'SLIZA.WIDGET.BACK_TO_STEP3': 'step3'
}
},
site_not_payed: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed',
'SLIZA.WIDGET.PAY': 'tariffs'
}
},
tariffs: {
on: {
'SLIZA.WIDGET.CLOSE': 'closed'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment