Skip to content

Instantly share code, notes, and snippets.

@mwarger
Created March 1, 2020 21:53
Show Gist options
  • Save mwarger/774cb156e99f6ee4bb2b8909e9f8b067 to your computer and use it in GitHub Desktop.
Save mwarger/774cb156e99f6ee4bb2b8909e9f8b067 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'fetch',
initial: 'idle',
context: {
retries: 0
},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: {
target: 'loading',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment