Last active
May 11, 2021 14:28
-
-
Save erikras/632e1e9f8756d463fb610d71907943c8 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
// 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