Last active
November 22, 2022 09:58
-
-
Save LevelbossMike/6642fb6fb6163f2ef6e8b90eddc7906d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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