Skip to content

Instantly share code, notes, and snippets.

@sagarPakhrin
Last active November 17, 2020 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagarPakhrin/fbbc06f093d4347ddde166cbc8cc314d to your computer and use it in GitHub Desktop.
Save sagarPakhrin/fbbc06f093d4347ddde166cbc8cc314d 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: 'filter',
initial: 'filtering',
context: {
filters: {
category: '',
item: '',
location: '',
date: '',
type: '',
},
pricelist: [],
items: [],
},
states: {
filtering: {
on: {
category: {
target: 'fetchStart',
actions: assign({
filters: ({filters}, event) => ({
...filters,
category: event.category,
}),
}),
},
type: {
target: 'fetchStart',
actions: assign({
filters: ({filters}, event) => ({...filters, category: event.type}),
}),
},
location: {
target: 'fetchStart',
actions: assign({
filters: ({filters}, event) => ({
...filters,
category: event.location,
}),
}),
},
item: {
target: 'fetchStart',
actions: assign({
filters: ({filters}, event) => ({...filters, category: event.item}),
}),
},
date: {
target: 'fetchStart',
actions: assign({
filters: ({filters}, event) => ({...filters, category: event.date}),
}),
},
},
},
fetchStart: {
on: {
DONE: 'filtering',
FAILED: 'failed'
}
},
failed: {
on: {
RETRY: 'filtering'
}
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment