Created
October 28, 2020 20:29
-
-
Save theClarkSell/cd4e889dd2a49186063cf8c789ed7ff7 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 fetchMachine = Machine( | |
{ | |
id: 'pagingMachine', | |
initial: 'init', | |
context: { | |
items: [], | |
cursor: null, | |
hasMore: false, | |
}, | |
states: { | |
init: { | |
meta: { | |
message: 'in initial state', | |
}, | |
invoke: { | |
id: 'initialLoad', | |
meta: { | |
message: 'calling load', | |
}, | |
src: 'load', | |
onDone: { | |
meta: { | |
message: 'loading item data success', | |
}, | |
actions: ['loadSuccess', 'setHasMore'], | |
target: 'loaded', | |
}, | |
onError: 'loadingFailed', | |
}, | |
}, | |
loadingNext: { | |
invoke: { | |
id: 'loadingNext', | |
meta: { | |
message: 'calling load next', | |
}, | |
src: 'loadNext', | |
onDone: [ | |
{ | |
meta: { | |
message: 'loading item next data was a success', | |
}, | |
cond: 'hasMore', | |
actions: ['loadNextSuccess'], | |
target: 'loaded', | |
}, | |
{ | |
target: 'loadedAll', | |
}, | |
], | |
onError: 'loadingFailed', | |
}, | |
}, | |
loaded: { | |
meta: { | |
message: 'item data loaded', | |
}, | |
on: { | |
NEXT: { | |
meta: { | |
message: 'event NEXT fired', | |
}, | |
target: 'loadingNext', | |
}, | |
REFRESH: { | |
meta: { | |
message: 'event REFRESH fired', | |
}, | |
target: 'init', | |
}, | |
}, | |
}, | |
loadedAll: { | |
meta: { | |
message: 'all possible data has been loaded', | |
}, | |
}, | |
loadingFailed: { | |
meta: { | |
message: 'loading has failed', | |
}, | |
entry: 'logError', | |
type: 'final', | |
}, | |
}, | |
} | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment