Skip to content

Instantly share code, notes, and snippets.

@LevelbossMike
Last active November 22, 2022 09:58
Show Gist options
  • Save LevelbossMike/6642fb6fb6163f2ef6e8b90eddc7906d to your computer and use it in GitHub Desktop.
Save LevelbossMike/6642fb6fb6163f2ef6e8b90eddc7906d 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({
type: 'parallel',
context: {},
states: {
interactivity: {
initial: 'unknown',
states: {
unknown: {
on: {
'': [
{
target: 'enabled',
cond: 'isEnabled'
},
{ target: 'disabled' }
],
},
},
enabled: {
on: {
DISABLE: 'disabled',
},
},
disabled: {
on: {
ENABLE: 'enabled',
},
},
},
},
activity: {
initial: 'idle',
states: {
idle: {
on: {
SUBMIT: {
target: 'busy',
cond: 'isEnabled',
},
},
},
busy: {
invoke: {
src: 'handleSubmit',
onDone: 'success',
onError: 'error'
}
},
success: {
entry: ['handleSuccess'],
on: {
SUBMIT: {
target: 'busy',
cond: 'isEnabled',
},
},
},
error: {
entry: ['handleError'],
on: {
SUBMIT: {
target: 'busy',
cond: 'isEnabled',
},
},
},
},
},
},
},
{
actions: {
handleSuccess() {},
handleError() {},
},
services: {
handleSubmit: async () => {}
},
guards: {
isEnabled(context) {
return !context.disabled;
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment