diff options
Diffstat (limited to 'src/reducers')
| -rw-r--r-- | src/reducers/index.js | 5 | ||||
| -rw-r--r-- | src/reducers/objects.js | 24 | ||||
| -rw-r--r-- | src/reducers/topology.js | 10 |
3 files changed, 30 insertions, 9 deletions
diff --git a/src/reducers/index.js b/src/reducers/index.js index 40a51a04..287a9762 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -2,7 +2,8 @@ import {combineReducers} from "redux"; import {auth} from "./auth"; import {modals} from "./modals"; import {objects} from "./objects"; -import {authorizationsOfCurrentUser, authVisibilityFilter} from "./simulations"; +import {authorizationsOfCurrentUser, authVisibilityFilter, currentSimulationId} from "./simulations"; +import {currentDatacenterId} from "./topology"; const rootReducer = combineReducers({ auth, @@ -10,6 +11,8 @@ const rootReducer = combineReducers({ modals, authorizationsOfCurrentUser, authVisibilityFilter, + currentSimulationId, + currentDatacenterId, }); export default rootReducer; diff --git a/src/reducers/objects.js b/src/reducers/objects.js index 60cd2711..4fbffea6 100644 --- a/src/reducers/objects.js +++ b/src/reducers/objects.js @@ -1,5 +1,5 @@ import {combineReducers} from "redux"; -import {ADD_TO_STORE} from "../actions/objects"; +import {ADD_PROP_TO_STORE_OBJECT, ADD_TO_STORE} from "../actions/objects"; export const objects = combineReducers({ simulation: object("simulation"), @@ -27,14 +27,22 @@ function object(type) { 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} - ); - } + 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)} + ); + } + + return state; }; } diff --git a/src/reducers/topology.js b/src/reducers/topology.js new file mode 100644 index 00000000..caafb7c1 --- /dev/null +++ b/src/reducers/topology.js @@ -0,0 +1,10 @@ +import {FETCH_LATEST_DATACENTER_SUCCEEDED} from "../actions/topology"; + +export function currentDatacenterId(state = -1, action) { + switch (action.type) { + case FETCH_LATEST_DATACENTER_SUCCEEDED: + return action.datacenterId; + default: + return state; + } +} |
