Skip to content

Instantly share code, notes, and snippets.

@tmbtech
Created October 7, 2019 20:02
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 tmbtech/ea0f0aea8445dfd5780638494bc2f62f to your computer and use it in GitHub Desktop.
Save tmbtech/ea0f0aea8445dfd5780638494bc2f62f 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({
id: 'provider_search_machine',
type: 'parallel',
context: {
searchValue: '',
searchResults: undefined,
errorMessage: '',
},
states: {
search: {
initial: 'idle',
states: {
idle: {
exit: 'updateSearchValue',
on: {
AUTO_SEARCH: {
target: 'autoCompleteSearchPending',
},
SEARCH: {
target: 'searchPending',
},
},
},
autoCompleteSearchPending: {
exit: 'updateSearchResults',
on: {
AUTO_COMPLETE: {
target: 'searchComplete',
},
},
},
searchPending: {
invoke: {
id: 'patientSearch',
src: 'patientSearch',
onDone: {
target: 'searchComplete',
actions: 'updateSearchResults',
},
onError: {
target: 'generalError',
actions: 'setErrorMessage',
},
},
},
searchComplete: {
on: {
AUTO_SEARCH: {
target: 'autoCompleteSearchPending',
actions: 'updateSearchValue',
},
SEARCH: {
target: 'searchPending',
actions: 'updateSearchValue',
},
MAGIC_LINK: {
target: 'magicLink',
},
},
},
magicLink: {
on: {
AUTO_COMPLETE: {
target: 'searchComplete',
},
},
},
generalError: {
on: {
SEARCH: {
target: 'searchPending',
actions: ['updateSearchValue', 'clearErrorMessage'],
},
},
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment