Skip to content

Instantly share code, notes, and snippets.

@ndisampson
Created February 6, 2020 05:57
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 ndisampson/bce521a58774eb7af734337e076fd6f6 to your computer and use it in GitHub Desktop.
Save ndisampson/bce521a58774eb7af734337e076fd6f6 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',
states: {
idle: {
on: { FETCH: 'loading' }
},
loading: {
after: {
3000: 'failure.timeout'
},
on: {
RESOLVE: 'success',
REJECT: 'failure',
TIMEOUT: 'failure.timeout' // manual timeout
},
meta: {
message: 'Loading...'
}
},
success: {
meta: {
message: 'The request succeeded!'
}
},
failure: {
initial: 'rejection',
states: {
rejection: {
meta: {
message: 'The request failed.'
}
},
timeout: {
meta: {
message: 'The request timed out.'
}
}
},
meta: {
alert: 'Uh oh.'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment