Skip to content

Instantly share code, notes, and snippets.

@erikras
Last active May 11, 2021 14:28
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 erikras/632e1e9f8756d463fb610d71907943c8 to your computer and use it in GitHub Desktop.
Save erikras/632e1e9f8756d463fb610d71907943c8 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 menuMachine = Machine({
id: 'menu',
initial: 'idle',
context: {},
invoke: [{src: 'listenForScroll'}, {src: 'iframe', id: 'iframe'}],
states: {
idle: {
on: {
EMBED_MENU_SHOW_ENTER_ORDER_FORM_VIEW_CONFIRM: 'formView',
EMBED_MENU_SHOW_ENTER_REQUEST_FORM_VIEW: 'formView',
EMBED_MENU_SHOW_ENTER_SHOW_VIEW: 'showView',
EMBED_MENU_SHOW_RESIZE: {
target: 'idle',
actions: 'resize',
},
SCROLL: {target: 'maybeLoadMore', actions: 'saveScroll'},
},
},
formView: {
on: {
VIEWING_PRODUCT_MENU: 'scrollingSoon',
},
},
loadingMore: {
entry: 'loadMore',
on: {
LOADED_MORE: {
target: 'idle',
actions: ['loadedMore', 'resize'],
},
},
},
maybeLoadMore: {
always: [
{
target: 'idle',
cond: 'doneLoading',
},
{
target: 'loadingMore',
cond: 'atInfiniteScrollThreshold',
},
{target: 'idle'},
],
},
scrollingSoon: {
after: {
10: [
// if we still have more to scroll, return here to try again
{
target: 'scrollingSoon',
cond: 'haveMoreToScroll',
actions: 'scroll',
},
{target: 'idle'},
],
},
},
showView: {
on: {
VIEWING_PRODUCT_MENU: 'scrollingSoon',
},
},
unmounted: {
type: 'final',
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment