Skip to content

Instantly share code, notes, and snippets.

@johnsonjo4531
Created July 28, 2020 21:50
Show Gist options
  • Save johnsonjo4531/0249bae6024febf9dfc9ec5422678aa1 to your computer and use it in GitHub Desktop.
Save johnsonjo4531/0249bae6024febf9dfc9ec5422678aa1 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({
initial: 'idle',
states: {
idle: {
after: {
500: [{
actions: [send('SET_SEARCH_TERM')],
cond: 'isNewSearch'
}]
},
on: {
SET_SEARCH_TERM: [{
actions: 'setSearchTerm',
target: 'querying',
cond: 'searchTimerThrottled',
}, {
target: 'idle',
cond: 'isNewSearch'
}],
},
},
querying: {
exit: 'resetSearchTimer',
invoke: {
src: 'getSearch',
onDone: {
actions: 'assignFeed',
target: 'idle',
},
// TODO: handle error
onError: {
actions: 'assignError',
target: 'idle',
}
},
},
},
on: {
LOAD_SEARCH: undefined,
SET_SEARCH_TERM: {
actions: 'setSearchTerm',
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment