Created
August 9, 2022 12:50
-
-
Save LevelbossMike/4eea061ac6b8eabe907a102c68c41f50 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const infiniteShifts = Machine({ | |
id: 'infinite-scrolling-shifts', | |
initial: 'noData', | |
states: { | |
noData: { | |
on: { | |
LOAD: 'loading' | |
} | |
}, | |
loading: { | |
invoke: { | |
src: 'loadInitialData', | |
onDone: 'data', | |
onError: 'error' | |
} | |
}, | |
data: { | |
initial: 'idle', | |
// all of these events will reset | |
// the data | |
on: { | |
// how do we refresh? can we refresh | |
// the entire dataset in one go? | |
REFRESH: 'loading', | |
// we need to reload everything | |
FILTERS_CHANGED: 'loading', | |
// this is weird in an infinite scroll | |
// => how do we display that? | |
// i.e. a user scrolls and then | |
// changes date -> what happens? | |
DATE_CHANGED: 'loading' | |
}, | |
states: { | |
// it looks like we need to figure out | |
// pagination ourselves here - do we | |
// calculate a proper meta ourselves | |
// base don page-size, records etc.? | |
idle: { | |
on: { | |
LOAD_NEXT: 'loading', | |
LOAD_PREV: 'loading', | |
} | |
}, | |
loading: { | |
invoke: { | |
src: 'loadPage', | |
onDone: 'success', | |
onError: 'error' | |
} | |
}, | |
success: { | |
// transition into idle immediately | |
// or animate if we want to be nice | |
}, | |
error: { | |
// how do we recover from an error here? | |
} | |
}, | |
}, | |
error: {} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment