Skip to content

Instantly share code, notes, and snippets.

@kbingman
Last active June 16, 2021 06:16
Show Gist options
  • Save kbingman/eb4e1fcfa67a5e6667c20a9aa8c58714 to your computer and use it in GitHub Desktop.
Save kbingman/eb4e1fcfa67a5e6667c20a9aa8c58714 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: 'fetch-machine',
initial: 'idle',
context: {
q: '',
offset: 0,
size: 10,
},
states: {
idle: {
id: 'idle',
on: {
SEARCH: {
target: 'selected',
},
},
},
selected: {
id: 'selected',
on: {
FETCH: {
target: 'pending',
},
},
states: {},
},
pending: {
invoke: {
id: 'fetch-results',
src: 'invokeFetchResults',
onDone: {
target: 'success',
actions: 'assignResults',
},
onError: 'failure',
},
},
success: {
on: {
SEARCH: {
target: '#selected',
},
FILTER: {
target: '#selected',
},
RESET: {
target: '#idle',
},
},
},
failure: {
on: {
SEARCH: {
target: '#selected',
},
RESET: {
target: '#idle',
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment