Created
November 16, 2019 21:30
-
-
Save cogell/343bd484b7c6ebebe568078578b6fcd7 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
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