Created
July 28, 2020 21:50
-
-
Save johnsonjo4531/0249bae6024febf9dfc9ec5422678aa1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
// 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