From eb208a7e2fd020ab5d07d11cc6d52d1e3dcfcc7c Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Sun, 17 Sep 2017 17:55:04 +0200 Subject: Add simulation mode framework Includes object states in the store (by tick), charting, and progress bars. --- src/reducers/states.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/reducers/states.js (limited to 'src/reducers/states.js') diff --git a/src/reducers/states.js b/src/reducers/states.js new file mode 100644 index 00000000..a9eb4ce8 --- /dev/null +++ b/src/reducers/states.js @@ -0,0 +1,33 @@ +import {combineReducers} from "redux"; +import {ADD_TO_STATES} from "../actions/states"; + +export const states = combineReducers({ + task: objectStates("task"), + room: objectStates("room"), + rack: objectStates("rack"), + machine: objectStates("machine"), +}); + +function objectStates(type) { + return (state = {}, action) => { + if (action.objectType !== type) { + return state; + } + + if (action.type === ADD_TO_STATES) { + return Object.assign( + {}, + state, + { + [action.tick]: Object.assign( + {}, + state[action.tick], + {[action.object.id]: action.object} + ) + } + ); + } + + return state; + }; +} -- cgit v1.2.3