Skip to content

Instantly share code, notes, and snippets.

@benfavre
Created November 22, 2019 11:27
Show Gist options
  • Save benfavre/1fd35572d9d9f9ba85175a6dd8acb11e to your computer and use it in GitHub Desktop.
Save benfavre/1fd35572d9d9f9ba85175a6dd8acb11e 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 fetchMachine = Machine({
id: 'fetch',
initial: 'unsavedDraft',
context: {
retries: 0
},
states: {
unsavedDraft: {
on: {
save: 'draft'
}
},
draft: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: {
target: 'draft',
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