Skip to content

Instantly share code, notes, and snippets.

@austinsamsel
Last active April 27, 2021 22:14
Show Gist options
  • Save austinsamsel/d4b7a0c082ad632ebf0cc4e5b9ecc0fb to your computer and use it in GitHub Desktop.
Save austinsamsel/d4b7a0c082ad632ebf0cc4e5b9ecc0fb 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 profileDefinition = {
initial: 'IDLE',
context: {
profile: null,
},
states: {
IDLE: {
on: {
GET_PROFILE: 'LOADING',
SET_NAME: 'UPDATING_NAME',
},
},
LOADING: {
invoke: {
id: 'LOADING',
// @NOTE: will be a service that fetches this from our API
src: 'fetchProfile',
onDone: {
target: 'IDLE',
actions: ['assignProfile'],
},
onError: 'IDLE',
},
},
UPDATING_NAME: {
invoke: {
id: 'UPDATING_NAME',
src: 'updateName',
onDone: 'TAIL_TX',
onError: 'IDLE',
},
},
TAIL_TX: {
invoke: {
id: 'TAIL_TX',
src: 'fetchProfile',
onDone: {
target: 'POLL_API',
actions: ['assignProfile'],
},
onError: 'IDLE',
},
},
POLL_API: {
// @TODO: for now just repeats the following step
invoke: {
id: 'POLL_API',
src: 'fetchProfile',
onDone: {
target: 'IDLE',
actions: ['assignProfile'],
},
onError: 'IDLE',
},
},
SUCCESS: {},
ERROR: {},
},
};
Machine(profileDefinition);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment