Skip to content

Instantly share code, notes, and snippets.

@yoni333
Last active September 11, 2022 19:36
Show Gist options
  • Save yoni333/b2d38a5fcc2cbb699e769a6f71cc5cf2 to your computer and use it in GitHub Desktop.
Save yoni333/b2d38a5fcc2cbb699e769a6f71cc5cf2 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: 'fetch',
initial: 'idle',
context: {
retries: 0
},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
on: {
RESOLVE: 'fetchMoreData',
REJECT: 'failure'
}
},
success: {
target:'fetchMoreData'
},
failure: {
on: {
RETRY: {
target: 'loading',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
},
fetchMoreData:{
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment