Skip to content

Instantly share code, notes, and snippets.

@cogell
Created November 16, 2019 21:30
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 cogell/343bd484b7c6ebebe568078578b6fcd7 to your computer and use it in GitHub Desktop.
Save cogell/343bd484b7c6ebebe568078578b6fcd7 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const selectHomeMachine2 = Machine({
id: 'selectHomeMachine',
initial: 'inviteSearch',
context: {
home: undefined,
searchQuery: '',
searchResults: '',
},
on: {
SUBMIT: [
{
target: 'loading',
actions: 'setSearchQuery',
cond: 'canSearch',
},
{
actions: 'setSearchQuery',
},
],
},
states: {
inviteSearch: {},
loading: {
initial: 'debouncing',
states: {
debouncing: {
entry: 'clearHome',
after: {
500: 'fetching',
},
},
fetching: {
invoke: {
src: 'requestSearchResults',
onDone: {
target: '#selectHomeMachine.results',
actions: 'setSearchResults',
},
onError: {
target: '#selectHomeMachine.noResults',
actions: 'setSearchResults',
},
},
},
},
},
noResults: {
id: 'noResults',
},
results: {
id: 'results',
on: {
TOGGLE_HOME: {
actions: 'toggleHomeContext',
},
NEXT: {
actions: 'handleNext',
cond: 'isHomeDefined',
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment