Skip to content

Instantly share code, notes, and snippets.

@elsangedy
Created September 12, 2019 20:11
Show Gist options
  • Save elsangedy/2917d54114fbeb47032582df1d884021 to your computer and use it in GitHub Desktop.
Save elsangedy/2917d54114fbeb47032582df1d884021 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'infinite scroll',
initial: 'idle',
context: {
page: 0,
size: 25
},
states: {
idle: {
on: {
FETCH: 'pending',
SCROLL: [
{
target: 'pending',
cond: 'isEndOfScroll'
},
{
target: 'idle'
}
]
}
},
pending: {
on: {
RESOLVE: [
{
target: 'idle',
cond: 'hasMore'
},
{
target: 'done'
}
],
REJECT: 'idle'
}
},
done: {
type: 'final'
}
}
},
{
guards: {
isEndOfScroll: context => console.log('isEndOfScroll', context) || Math.random() > .5,
hasMore: context => console.log('hasMore', context) || Math.random() > .5
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment