Skip to content

Instantly share code, notes, and snippets.

@ImadBoumzaoued
Created April 21, 2020 18:30
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 ImadBoumzaoued/4238c5f8fd959af3079a92f446077225 to your computer and use it in GitHub Desktop.
Save ImadBoumzaoued/4238c5f8fd959af3079a92f446077225 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'login-machine',
initial: 'idle',
context: {
retries: 0,
message: undefined
},
states: {
idle: {
on: {
LOGIN: 'pending'
}
},
pending: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
type: 'final'
},
failure: {
on: {
LOGIN: {
target: 'pending',
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