diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-08-25 17:48:12 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:05:44 +0200 |
| commit | c47a27b826f7d76410308a4151611a366f9eaf46 (patch) | |
| tree | c1ca374204714cedabcacb8620848b903a0bf8d6 /src/store | |
| parent | 1ddbbd3563af77a218020021ea50a8832900b4db (diff) | |
Fetch and display datacenter topology
Diffstat (limited to 'src/store')
| -rw-r--r-- | src/store/configureStore.js | 2 | ||||
| -rw-r--r-- | src/store/denormalizer.js | 20 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/store/configureStore.js b/src/store/configureStore.js index ecd804a2..5bbaf811 100644 --- a/src/store/configureStore.js +++ b/src/store/configureStore.js @@ -3,9 +3,9 @@ import persistState from "redux-localstorage"; import {createLogger} from "redux-logger"; import createSagaMiddleware from 'redux-saga'; import thunk from "redux-thunk"; -import rootSaga from "../api/sagas/index"; import {authRedirectMiddleware} from "../auth/index"; import rootReducer from "../reducers/index"; +import rootSaga from "../sagas/index"; const sagaMiddleware = createSagaMiddleware(); const logger = createLogger(); diff --git a/src/store/denormalizer.js b/src/store/denormalizer.js index fbf15430..e6583ae7 100644 --- a/src/store/denormalizer.js +++ b/src/store/denormalizer.js @@ -1,14 +1,28 @@ +const EXCLUDED_IDENTIFIERS = [ + "objectId", + "googleId", +]; + export function denormalize(state, objectType, id) { + return denormalizeWithRecursionCheck(state, objectType, id, undefined); +} + +function denormalizeWithRecursionCheck(state, objectType, id, previousType) { const object = Object.assign({}, state.objects[objectType][id]); for (let prop in object) { - if (!object.hasOwnProperty(prop)) { + if (prop.indexOf(previousType) !== -1) { continue; } - if (prop.endsWith("Id")) { + if (prop.endsWith("Id") && EXCLUDED_IDENTIFIERS.indexOf(prop) === -1) { const propType = prop.replace("Id", ""); - object[propType] = state.objects[propType][object[prop]]; + object[propType] = denormalizeWithRecursionCheck(state, propType, object[prop], objectType); + } + + if (prop.endsWith("Ids")) { + const propType = prop.replace("Ids", ""); + object[propType + "s"] = object[prop].map(id => denormalizeWithRecursionCheck(state, propType, id, objectType)); } } |
