Skip to content

Instantly share code, notes, and snippets.

@pke
Last active August 24, 2021 09:02
Show Gist options
  • Save pke/7f219282076a0390408733892bfdeef1 to your computer and use it in GitHub Desktop.
Save pke/7f219282076a0390408733892bfdeef1 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: 'doctorsearch',
initial: 'speciality',
context: {
speciality: "",
location: undefined,
showFilter: false,
filters: [],
showDetails: false,
},
states: {
speciality: {
on: {
SET_SPECIALITY: {
target: 'location',
cond: "validateSpeciality",
actions: "setSpeciality"
}
}
},
location: {
on: {
SET_LOCATION: {
target: 'search',
cond: (context, event) => !!event.value,
actions: "setLocation"
}
}
},
search: {
on: {
TOGGLE_DETAIL: {
actions: assign({
showDetails: (context, event) => !context.showDetails
})
}
}
},
}
}, {
guards: {
validateSpeciality: (context, event) => !!event.value
},
actions: {
setSpeciality: assign({
location: (context, event) => event.value
}),
setLocation: assign({
location: (context, event) => event.value
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment