Skip to content

Instantly share code, notes, and snippets.

@barbados-clemens
Last active August 19, 2020 21:26
Show Gist options
  • Save barbados-clemens/4a78aae66feab67f9e90be4423a672da to your computer and use it in GitHub Desktop.
Save barbados-clemens/4a78aae66feab67f9e90be4423a672da to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
//https://xstate.js.org/viz/?gist=4a78aae66feab67f9e90be4423a672da
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const clientMachine = Machine({
id: 'client',
initial: 'loading',
context: {
retries: 0,
client: undefined
},
states: {
loading: {
on: {
RESOLVE: {
target: 'success',
actions: assign({
retries: 0,
client: {
id: 123,
}
})
},
REJECT: 'failure'
}
},
success: {
on: {
REFRESH: {
target:'loading',
actions: assign({
retries: 0,
client: {}
})
},
}
},
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