Skip to content

Instantly share code, notes, and snippets.

@pangratz
Last active April 23, 2020 07:24
Show Gist options
  • Select an option

  • Save pangratz/b4b4f5179de444ab87747b0060b69b95 to your computer and use it in GitHub Desktop.

Select an option

Save pangratz/b4b4f5179de444ab87747b0060b69b95 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: 'order-sequencing',
type: "parallel",
states: {
calendar: {
type: "parallel",
states: {
mode: {
initial: 'week',
states: {
day: {
on: {
SHOW_WEEK: {
target: "week",
actions: ["setFilterToWeek", send("LOAD")]
},
SHOW_TODAY: {
actions: ["setFilterToToday", send("LOAD")]
},
BEFORE: {
actions: ["setFilterToDayBefore", send("LOAD")]
},
AFTER: {
actions: ["setFilterToDayAfter", send("LOAD")]
}
}
},
week: {
on: {
SHOW_DAY: {
target: "day",
actions: ["setFilterToBeginningOfWeek", send("LOAD")]
},
SHOW_TODAY: {
actions: ["setFilterToToday", send("LOAD")]
},
BEFORE: {
actions: ["setFilterToWeekBefore", send("LOAD")]
},
AFTER: {
actions: ["setFilterToWeekAfter", send("LOAD")]
}
}
}
}
},
// data for listing production schedule items for currently set filer
data: {
initial: "idle",
states: {
idle: {
on: {
LOAD: "loading"
},
after: {
10000: "loading"
}
},
loading: {
onEntry: [send("LOAD")],
on: {
LOAD: {
actions: ["loadProductionScheduleItemsForCurrentFilter"]
},
LOAD_SUCCESS: "success",
LOAD_ERROR: "error"
}
},
success: {
onEntry: ["setListOfProductionScheduleItems"],
on: {
"": "idle"
}
},
error: {
onEntry: ["showErrorToUser"]
}
}
}
}
},
workflow: {
type: "parallel",
states: {
mode: {
initial: "read",
states: {
read: {
on: {
START_EDITING: "write"
}
},
write: {
type: "parallel",
on: {
STOP_EDITING: "read"
},
states: {
production_orders: {
initial: "empty",
states: {
empty: {
on: {
SELECTION_UPDATED: "selection"
}
},
selection: {
on: {
SELECTION_UPDATED: [
{
target: "empty",
cond: "emptySelection"
}
]
}
}
}
},
production_schedule_item: {
initial: "empty",
states: {
empty: {
on: {
CLICKED_ITEM: {
target: "selection"
}
}
},
selection: {
onEntry: ["setItem"],
on: {
CLICKED_ITEM: [{
target: "empty",
cond: "isSameItem"
}, {
target: "selection"
}],
MOVE_UP: {
actions: ["moveUp", send("SAVE")]
},
MOVE_DOWN: {
actions: ["moveDown", send("SAVE")]
},
REMOVE_FROM_PLANNING: {
target: "empty",
actions: ["removeFromPlanning", send("SAVE")]
}
}
}
}
}
}
}
}
},
data: {
initial: "idle",
states: {
idle: {
on: {
SAVE: {
target: "saving"
}
}
},
saving: {
onEntry: ["save"],
on: {
SAVE_SUCCESS: "success",
SAVE_ERROR: "error"
}
},
success: {
onEntry: ["load", send("LOAD")],
on: {
"": "idle"
}
},
error: {}
}
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment