Skip to content

Instantly share code, notes, and snippets.

@jtiala
Created October 28, 2020 15:32
Show Gist options
  • Save jtiala/793757b9d89701f121ac90f83c0a8c64 to your computer and use it in GitHub Desktop.
Save jtiala/793757b9d89701f121ac90f83c0a8c64 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const bookingMachine = Machine({
id: "booking",
initial: "idle",
context: {
fetched: {
purposes: undefined,
specifiers: undefined,
servicePoints: undefined,
appointmentTypes: undefined,
},
selected: {
purpose: undefined,
specifiers: undefined,
appointmentType: undefined,
},
},
states: {
idle: {
on: {
NEXT: "fetchPurposes",
},
},
fetchPurposes: {
invoke: {
id: "fetchPurposes",
onDone: {
target: "selectPurpose",
actions: assign({
fetched: (context, event) => ({
purposes: event.data,
specifiers: event.data,
}),
}),
},
onError: "failure",
},
},
selectPurpose: {
on: {
NEXT: "selectSpecifiers",
},
},
selectSpecifiers: {
on: {
NEXT: "fetchServicePoints",
},
},
fetchServicePoints: {
invoke: {
id: "fetchServicePoints",
onDone: {
target: "selectAppointmentType",
actions: assign({
fetched: (context, event) => ({
servicePoints: event.data,
appointmentTypes,
}),
}),
},
onError: "failure",
},
},
selectAppointmentType: {},
ready: {
type: "final",
},
failure: {
type: "final",
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment