Created
January 17, 2020 19:13
-
-
Save barucAlmaguer/e0386b0f9ab773f0c4c331677fe6adbb to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const CoilScheduleMachine = Machine({ | |
id: 'CoilSchedule', | |
context: { | |
job: {}, | |
csv: [], | |
balances: [], | |
startAt: null, | |
coilsPath: null, | |
railsPath: null, | |
errors: [], | |
coilPlanId: null, | |
coilPlan: null, | |
railSequences: null, | |
selectedCoil: null | |
}, | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
SET_INPUTS: { target: 'setting_inputs' }, | |
VIEW_PLAN: { | |
target: 'viewing_plan', | |
actions: ['setCoilPlanId'] | |
}, | |
} | |
}, | |
setting_inputs: { | |
on: { | |
START_PLANNER: { | |
target: 'planning_coil_schedule', | |
actions: [ | |
'setBalances', | |
'setStartAt', | |
'setCoilsPath', | |
'setRailsPath' | |
] | |
}, | |
BACK: 'idle' | |
} | |
}, | |
planning_coil_schedule: { | |
initial: 'starting', | |
states: { | |
starting: { | |
on: { | |
RESOLVE: { | |
target: 'planning', | |
actions: ['updateJob'] | |
}, | |
REJECT: 'error' | |
} | |
}, | |
planning: { | |
on: { | |
UPDATE: { | |
target: 'planning', | |
actions: ['updateJob'] | |
}, | |
SUCCESS: { | |
target: '#CoilSchedule.viewing_plan', | |
actions: [ | |
'updateJob', | |
'setCoilPlanId' | |
] | |
}, | |
ERROR: 'error' | |
} | |
}, | |
error: { | |
on: { | |
BACK: '#CoilSchedule.setting_inputs' | |
} | |
} | |
} | |
}, | |
viewing_plan: { | |
type: 'parallel', | |
states: { | |
ui: { | |
initial: 'fetching_plan', | |
entry: ['fetchCoilPlan'], | |
states: { | |
fetching_plan: { | |
on: { | |
RESOLVE: { | |
target: 'viewing_coil_plan', | |
actions: ['setCoilPlan'] | |
}, | |
REJECT: { | |
target: 'no_plan_found', | |
actions: ['showFlashAlert'] | |
} | |
} | |
}, | |
viewing_coil_plan: { | |
on: { | |
VIEW_RAILS: 'viewing_rail_plan', | |
RESET: '#CoilSchedule.idle' | |
} | |
}, | |
viewing_rail_plan: { | |
on: { | |
BACK: 'viewing_coil_plan', | |
RESET: '#CoilSchedule.idle' | |
} | |
}, | |
no_plan_found: { | |
on: { | |
RESET: '#CoilSchedule.idle' | |
} | |
}, | |
} | |
}, | |
rail_fetcher: { | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
START_RAIL_FETCH: 'fetching_rail' | |
} | |
}, | |
fetching_rail: { | |
entry: 'fetchRail', | |
on: { | |
RESOLVE_RF: [ | |
{ | |
target: 'finished', | |
actions: ['appendRail'], | |
cond: { type: 'railFetchFinished' } | |
}, | |
{ | |
target: 'fetching_rail', | |
} | |
], | |
REJECT_RF: [ | |
{ | |
target: 'finished', | |
actions: ['appendBadRail'], | |
cond: { type: 'railFetchFinished' } | |
}, | |
{ | |
target: 'fetching_rail', | |
} | |
], | |
} | |
}, | |
finished: { | |
type: 'final' | |
} | |
} | |
} | |
} | |
}, | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment