Skip to content

Instantly share code, notes, and snippets.

@austinsamsel
Last active March 20, 2021 16:45
Show Gist options
  • Save austinsamsel/53ada8eca2460a453b3cfdf9c78ad580 to your computer and use it in GitHub Desktop.
Save austinsamsel/53ada8eca2460a453b3cfdf9c78ad580 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: 'p2p-listing-purchase',
initial: 'idle',
context: {},
states: {
idle: {
id: 'idle',
on: {
SELECT: '#select',
},
},
select: {
id: 'select',
initial: 'fetch',
on: {
CANCEL: '#idle',
REFETCH: '#select.fetch',
},
states: {
fetch: {
invoke: {
src: 'getListings',
onDone: [
{
target: '#select.idle',
cond: 'listingHasMoments',
actions: ['assignGetListings'],
},
{
target: '#select.empty',
},
],
onError: '#select.error',
},
},
fetch_more: {
invoke: {
src: 'getListings',
onDone: [
{
target: '#select.idle',
actions: ['assignGetListings'],
},
],
onError: {
target: '#select.idle',
actions: ['assignFetchMoreError'],
},
},
},
idle: {
on: {
SET_SORT: {
target: '#select.fetch',
},
FETCH_MORE: {
target: '#select.fetch_more',
cond: 'isPaginationEnabled',
},
BUY: '#buyingMoment',
},
},
empty: {
},
error: {
},
},
},
buyingMoment: {
id: 'buyingMoment',
invoke: {
id: 'buyMoment',
src: 'buyMoment',
onDone: '#success',
onError: '#error',
},
},
error: {
id: 'error',
on: {
RETRY: '#select',
},
},
success: {
id: 'success',
type: 'final',
},
},
}, {
actions: {
assignGetListings: () => {},
assignFetchMoreError: () => {},
},
guards: {
listingHasMoments: () => true,
isPaginationEnabled: () => true,
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment