Skip to content

Instantly share code, notes, and snippets.

@pangratz
Last active April 23, 2020 07:24
Show Gist options
  • Save pangratz/b4b4f5179de444ab87747b0060b69b95 to your computer and use it in GitHub Desktop.
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: [
'setFilterToCurrentWeek',
send('LOAD_PRODUCTION_SCHEDULE_ITEMS')
]
},
SHOW_TODAY: {
actions: [
'setFilterToToday',
send('LOAD_PRODUCTION_SCHEDULE_ITEMS')
]
},
BEFORE: {
actions: [
'setFilterToDayBefore',
send('LOAD_PRODUCTION_SCHEDULE_ITEMS')
]
},
AFTER: {
actions: [
'setFilterToDayAfter',
send('LOAD_PRODUCTION_SCHEDULE_ITEMS')
]
}
}
},
week: {
on: {
SHOW_DAY: {
target: 'day',
actions: [
'setFilterToBeginningOfWeek',
send('LOAD_PRODUCTION_SCHEDULE_ITEMS')
]
},
SHOW_TODAY: {
actions: [
'setFilterToToday',
send('LOAD_PRODUCTION_SCHEDULE_ITEMS')
]
},
BEFORE: {
actions: [
'setFilterToWeekBefore',
send('LOAD_PRODUCTION_SCHEDULE_ITEMS')
]
},
AFTER: {
actions: [
'setFilterToWeekAfter',
send('LOAD_PRODUCTION_SCHEDULE_ITEMS')
]
}
}
}
}
},
data: {
initial: 'idle',
states: {
idle: {
on: {
LOAD: 'loading'
},
after: {
REFRESH_RATE: 'loading'
}
},
loading: {
entry: [send('LOAD_PRODUCTION_SCHEDULE_ITEMS')],
on: {
LOAD_PRODUCTION_SCHEDULE_ITEMS: {
actions: ['loadProductionScheduleItemsForCurrentFilter']
},
LOAD_PRODUCTION_SCHEDULE_ITEMS_SUCCESS: 'success',
LOAD_PRODUCTION_SCHEDULE_ITEMS_ERROR: 'error'
}
},
success: {
entry: ['setListOfProductionScheduleItems'],
on: {
'': 'idle'
}
},
error: {
entry: ['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'
}
],
PUT_TO_PLANNED: {
actions: [
'createProductionScheduleItemsForSelection',
send('SAVE_PRODUCTION_SCHEDULE_ITEMS')
]
}
}
}
}
},
production_schedule_item: {
initial: 'empty',
states: {
empty: {
on: {
CLICKED_ITEM: {
target: 'selection'
}
}
},
selection: {
entry: ['setItem'],
on: {
CLICKED_ITEM: [
{
target: 'empty',
cond: 'isSameItem'
},
{
// ensure we are re-transitioning so `setItem` is called
target: 'selection'
}
],
MOVE_UP: {
actions: [
'moveUp',
send('SAVE_PRODUCTION_SCHEDULE_ITEMS')
]
},
MOVE_DOWN: {
actions: [
'moveDown',
send('SAVE_PRODUCTION_SCHEDULE_ITEMS')
]
},
REMOVE_FROM_PLANNING: {
target: 'empty',
actions: [
'removeFromPlanning',
send('SAVE_PRODUCTION_SCHEDULE_ITEMS')
]
}
}
}
}
}
}
}
}
},
data: {
type: 'parallel',
states: {
production_orders: {
initial: 'idle',
states: {
idle: {
on: {
LOAD_PRODUCTION_ORDERS: {
target: 'loading'
}
},
after: {
REFRESH_RATE: 'loading'
}
},
loading: {
entry: ['loadProductionOrders'],
on: {
LOAD_PRODUCTION_ORDERS_SUCCESS: 'success',
LOAD_PRODUCTION_ORDERS_ERROR: 'error'
}
},
success: {
entry: ['setProductionOrders'],
on: {
'': 'idle'
}
},
error: {}
}
},
production_schedule_items: {
initial: 'idle',
states: {
idle: {
on: {
SAVE_PRODUCTION_SCHEDULE_ITEMS: {
target: 'saving'
}
}
},
saving: {
entry: ['saveProductionScheduleItems'],
on: {
SAVE_PRODUCTION_SCHEDULE_ITEMS_SUCCESS: 'success',
SAVE_PRODUCTION_SCHEDULE_ITEMS_ERROR: 'error'
}
},
success: {
entry: ['setProductionScheduleItems'],
on: {
'': 'idle'
}
},
error: {}
}
}
}
}
}
}
}
}, {
delays: {
REFRESH_RATE: 10000
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment