Skip to content

Instantly share code, notes, and snippets.

@abruzzi
Last active December 20, 2022 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abruzzi/99cc6141c8f25e5f79be0dfc98070e06 to your computer and use it in GitHub Desktop.
Save abruzzi/99cc6141c8f25e5f79be0dfc98070e06 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 shouldRetry = (context, event) => {
return context.retries < 3;
};
const fetchMachine = Machine({
id: 'Order Status',
initial: 'idle',
context: {
retries: 0
},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
on: {
RESOLVE: 'ready',
NOT_READY: [
{
target: 'failure',
cond: shouldRetry
},
{
target: 'error'
}
]
}
},
ready: {
on: {
NOTIFY: 'notified',
ERROR: 'error'
}
},
success: {
type: 'final'
},
notified: {
type: 'final'
},
error: {
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