diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-08-31 17:59:51 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:05:50 +0200 |
| commit | 3f736cd3db63f106eac02f220477b4a0f3b0eceb (patch) | |
| tree | 80afa73f8c4d281b2fccba8ad2baa7c10f7e7e84 /src/reducers/objects.js | |
| parent | b17f1d8cb4815f57a4b7043cc91b867ec3cbc867 (diff) | |
Implement room creation
Diffstat (limited to 'src/reducers/objects.js')
| -rw-r--r-- | src/reducers/objects.js | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/reducers/objects.js b/src/reducers/objects.js index 4fbffea6..801a5456 100644 --- a/src/reducers/objects.js +++ b/src/reducers/objects.js @@ -1,5 +1,10 @@ import {combineReducers} from "redux"; -import {ADD_PROP_TO_STORE_OBJECT, ADD_TO_STORE} from "../actions/objects"; +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"; export const objects = combineReducers({ simulation: object("simulation"), @@ -33,14 +38,40 @@ function objectWithId(type, getId) { 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; |
