Skip to content

Instantly share code, notes, and snippets.

@rschwabco
Last active January 26, 2021 21:07
Show Gist options
  • Save rschwabco/49434d96d65c516213eab6db3c3bc372 to your computer and use it in GitHub Desktop.
Save rschwabco/49434d96d65c516213eab6db3c3bc372 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: "fleet-machine",
initial: "idle",
context: {
selectedRequirement: {},
schedule: {},
},
states: {
idle: {
// * fetch fleet schedule immediately
initial: "loading",
context: {
schedule: {},
selectedRequirement: {},
},
states: {
loading: {
invoke: {
id: "fetch-fleet-schedule",
src: "getFleetSchedule",
onDone: {
target: "loaded",
actions: assign({
schedule: (context, event) =>
event.data.schedule,
}),
},
onError: {
target: "failure",
},
},
},
loaded: {
type: "final",
},
failure: {
on: {
RETRY: "loading",
},
},
},
},
selected: {
initial: "showRequirementActionForm",
context: {
selectedAction: {}
},
states: {
act1: {},
act2: {},
act3: {}
}
}
},
on: {
SELECT: {
target: ".selected",
actions: assign({
selectedRequirement: (_, event) => event.requirement,
}),
},
REFRESH_FLEET_SCHEDULE: {
target: "idle.loading",
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment