diff options
| author | Georgios Andreadis <info@gandreadis.com> | 2020-07-01 13:33:31 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-08-24 19:47:17 +0200 |
| commit | de8f12d74faef5fa3f9e38d1340948cab2d06ea3 (patch) | |
| tree | 678bf1af3e5fa2334f0df43388d45294785bbf1e /frontend/src/reducers/objects.js | |
| parent | 44236756c4cf689806dc17c6950a2cff3e9227bf (diff) | |
Manually generate IDs
Diffstat (limited to 'frontend/src/reducers/objects.js')
| -rw-r--r-- | frontend/src/reducers/objects.js | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/frontend/src/reducers/objects.js b/frontend/src/reducers/objects.js index 99d91092..2e9644d0 100644 --- a/frontend/src/reducers/objects.js +++ b/frontend/src/reducers/objects.js @@ -1,80 +1,80 @@ -import { combineReducers } from "redux"; +import { combineReducers } from 'redux' import { - ADD_ID_TO_STORE_OBJECT_LIST_PROP, - ADD_PROP_TO_STORE_OBJECT, - ADD_TO_STORE, - REMOVE_ID_FROM_STORE_OBJECT_LIST_PROP -} from "../actions/objects"; + ADD_ID_TO_STORE_OBJECT_LIST_PROP, + ADD_PROP_TO_STORE_OBJECT, + ADD_TO_STORE, + REMOVE_ID_FROM_STORE_OBJECT_LIST_PROP, +} from '../actions/objects' export const objects = combineReducers({ - 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"), - task: object("task"), - job: object("job"), - trace: object("trace"), - scheduler: object("scheduler"), - experiment: object("experiment") -}); + 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'), + task: object('task'), + job: object('job'), + trace: object('trace'), + scheduler: object('scheduler'), + experiment: object('experiment'), +}) function object(type) { - return objectWithId(type, object => object.id); + return objectWithId(type, object => object.id) } function objectWithId(type, getId) { - return (state = {}, action) => { - if (action.objectType !== type) { - return state; - } + return (state = {}, action) => { + if (action.objectType !== type) { + return state + } - if (action.type === ADD_TO_STORE) { - return Object.assign({}, state, { - [getId(action.object)]: action.object - }); - } else if (action.type === ADD_PROP_TO_STORE_OBJECT) { - return Object.assign({}, state, { - [action.objectId]: Object.assign( - {}, - state[action.objectId], - action.propObject - ) - }); - } else if (action.type === ADD_ID_TO_STORE_OBJECT_LIST_PROP) { - return Object.assign({}, state, { - [action.objectId]: Object.assign({}, state[action.objectId], { - [action.propName]: [ - ...state[action.objectId][action.propName], - action.id - ] - }) - }); - } else if (action.type === REMOVE_ID_FROM_STORE_OBJECT_LIST_PROP) { - return Object.assign({}, state, { - [action.objectId]: Object.assign({}, state[action.objectId], { - [action.propName]: state[action.objectId][action.propName].filter( - id => id !== action.id - ) - }) - }); - } + if (action.type === ADD_TO_STORE) { + return Object.assign({}, state, { + [getId(action.object)]: action.object, + }) + } else if (action.type === ADD_PROP_TO_STORE_OBJECT) { + return Object.assign({}, state, { + [action.objectId]: Object.assign( + {}, + state[action.objectId], + action.propObject, + ), + }) + } else if (action.type === ADD_ID_TO_STORE_OBJECT_LIST_PROP) { + return Object.assign({}, state, { + [action.objectId]: Object.assign({}, state[action.objectId], { + [action.propName]: [ + ...state[action.objectId][action.propName], + action.id, + ], + }), + }) + } else if (action.type === REMOVE_ID_FROM_STORE_OBJECT_LIST_PROP) { + return Object.assign({}, state, { + [action.objectId]: Object.assign({}, state[action.objectId], { + [action.propName]: state[action.objectId][action.propName].filter( + id => id !== action.id, + ), + }), + }) + } - return state; - }; + return state + } } |
