Skip to content

Instantly share code, notes, and snippets.

@cmd-save
Created November 23, 2020 19:32
Show Gist options
  • Select an option

  • Save cmd-save/0f5f98f5d9a76d47ab7d016c6f70febf to your computer and use it in GitHub Desktop.

Select an option

Save cmd-save/0f5f98f5d9a76d47ab7d016c6f70febf 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: 'search',
initial: 'idle',
context: {
result: {},
totalCount: 0
},
on: {
SEARCH: [
{
target: 'searching',
cond: {
type: 'search query has more than one character'
}
},
{
target: 'idle',
actions: ['resetSearchResult']
}
]
},
states: {
idle: {},
searching: {
invoke: {
id: 'searchService',
src: 'searchService',
onDone: {
target: 'loaded',
actions: ['storeResult']
},
onError: {
target: 'failure',
actions: assign({
error: (_, e)=>console.log('onError', e.data)
})
}
}
},
loaded: {},
failure: {}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment