Skip to content

Instantly share code, notes, and snippets.

@entorenee
Created July 21, 2020 22:15
Show Gist options
  • Save entorenee/286ef0ee6e79d01f2380084e899b3379 to your computer and use it in GitHub Desktop.
Save entorenee/286ef0ee6e79d01f2380084e899b3379 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',
context: {
results: [],
errorMessage: '',
},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
on: {
// SUCCESS: 'success',
SUCCESS: {
target: 'success',
actions: 'setResults',
},
FAILURE: {
target: 'failure',
actions: 'setError',
}
}
},
success: {
on: {
FETCH: 'loading'
}
},
failure: {
on: {
FETCH: 'loading'
}
}
}
}, {
actions: {
setResults: assign({
results: (context, event) => event.data
}),
setError: assign({
errorMesssage: (context, event) => event.message
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment