Skip to content

Instantly share code, notes, and snippets.

@oscargm
Last active December 3, 2019 10:20
Show Gist options
  • Save oscargm/2c26dac9f89838b6a661bf93364347d9 to your computer and use it in GitHub Desktop.
Save oscargm/2c26dac9f89838b6a661bf93364347d9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'fetch',
initial: 'idle',
context: {
selectedStatus: null
},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
after: {
3000: 'failure.timeout'
},
on: {
RESOLVE: 'success',
REJECT: 'failure.rejection',
TIMEOUT: 'failure.timeout' // manual timeout
},
},
success: {
on: {
SELECTSTATUS: 'statusSelected'
}
},
failure: {
type: 'final',
initial: 'rejection',
states: {
rejection: {
meta: {
message: 'The request failed.'
}
},
timeout: {
meta: {
message: 'The request timed out.'
}
}
},
},
statusSelected: {
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment