Skip to content

Instantly share code, notes, and snippets.

@thejettdurham
Created March 10, 2020 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejettdurham/9c9335e6736b281d84c36acb3565ad94 to your computer and use it in GitHub Desktop.
Save thejettdurham/9c9335e6736b281d84c36acb3565ad94 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'memberSearchMachine',
initial: 'dataEntry',
context: {
data: {},
validationErrors: {},
apiClient: {},
history: {},
},
states: {
'dataEntry': {
on: {
ENTER_DATA: {
actions: 'updateData',
},
SUBMIT: {
target: 'awaitingSubmitResponse',
},
},
},
'awaitingSubmitResponse': {
invoke: {
id: 'submitResponse',
src: 'fetchSearch',
},
on: {
SEARCH_SUCCESS: {
target: 'hasSearchResults',
actions: 'updateResults',
},
SEARCH_FAILURE: {
target: 'hasSearchError',
actions: 'updateValidationErrors',
},
},
},
'hasSearchError': {
on: {
ENTER_DATA: {
target: 'dataEntry',
actions: 'updateData',
},
},
},
'hasSearchResults': {
on: {
BACK: {
target: 'dataEntry',
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment