Skip to content

Instantly share code, notes, and snippets.

@AndreAffonso
Last active January 6, 2021 16:17
Show Gist options
  • Save AndreAffonso/262482689ac6f4eef0f08e4934757b6c to your computer and use it in GitHub Desktop.
Save AndreAffonso/262482689ac6f4eef0f08e4934757b6c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Idle
// - loading
// - not found
// - Instructions
// - Step Details
// - Camera
// - Done
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'fetch',
initial: 'idle',
context: {
retries: 0
},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
on: {
CREATE: 'instructions',
CONTINUE: 'stepDetails',
ERROR: 'failure',
NOT_FOUND: 'notFound'
}
},
instructions: {
on: {
START: 'stepDetails',
}
},
stepDetails: {
on: {
NEXT: 'camera'
}
},
camera: {
on: {
NEXT: 'stepDetails',
DONE: 'finished'
}
},
finished: {
type: 'final'
},
notFound: {
type: 'final'
},
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