diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-08-22 17:08:55 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:05:44 +0200 |
| commit | 1ddbbd3563af77a218020021ea50a8832900b4db (patch) | |
| tree | 5647f9cfde2de3918eeeac58d6c598bb55e50d82 /src/reducers | |
| parent | 602c3eb9327a3681f5a220e13b8291bb60643cd7 (diff) | |
Add route logic for construction routes
Diffstat (limited to 'src/reducers')
| -rw-r--r-- | src/reducers/objects.js | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/src/reducers/objects.js b/src/reducers/objects.js index 6381c8d9..60cd2711 100644 --- a/src/reducers/objects.js +++ b/src/reducers/objects.js @@ -1,44 +1,40 @@ import {combineReducers} from "redux"; -import {ADD_TO_AUTHORIZATION_STORE, ADD_TO_SIMULATION_STORE, ADD_TO_USER_STORE} from "../actions/objects"; +import {ADD_TO_STORE} from "../actions/objects"; export const objects = combineReducers({ - simulation, - authorization, - user, + simulation: object("simulation"), + user: object("user"), + authorization: objectWithId("authorization", object => [object.userId, object.simulationId]), + failureModel: object("failureModel"), + cpu: object("cpu"), + gpu: object("gpu"), + memory: object("memory"), + storage: object("storage"), + machine: object("machine"), + rack: object("rack"), + coolingItem: object("coolingItem"), + psu: object("psu"), + tile: object("tile"), + room: object("room"), + datacenter: object("datacenter"), + section: object("section"), + path: object("path"), }); -function simulation(state = {}, action) { - switch (action.type) { - case ADD_TO_SIMULATION_STORE: - return Object.assign( - state, - {[action.simulation.id]: action.simulation} - ); - default: - return state; - } -} - -function authorization(state = {}, action) { - switch (action.type) { - case ADD_TO_AUTHORIZATION_STORE: - return Object.assign( - state, - {[[action.authorization.userId, action.authorization.simulationId]]: action.authorization} - ); - default: - return state; - } +function object(type) { + return objectWithId(type, object => object.id); } -function user(state = {}, action) { - switch (action.type) { - case ADD_TO_USER_STORE: - return Object.assign( - state, - {[action.user.id]: action.user} - ); - default: +function objectWithId(type, getId) { + return (state = {}, action) => { + if (action.type === ADD_TO_STORE) { + if (action.objectType === type) { + return Object.assign( + state, + {[getId(action.object)]: action.object} + ); + } return state; - } + } + }; } |
