aboutsummaryrefslogtreecommitdiff
path: root/modern/src/reducers/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/reducers/index.js')
-rw-r--r--modern/src/reducers/index.js16
1 files changed, 11 insertions, 5 deletions
diff --git a/modern/src/reducers/index.js b/modern/src/reducers/index.js
index ac592bf..4593d1f 100644
--- a/modern/src/reducers/index.js
+++ b/modern/src/reducers/index.js
@@ -1,20 +1,26 @@
const initialState = {
- devices: [],
- positions: [],
- events: []
+ devices: new Map(),
+ positions: new Map()
};
+function updateMap(map, array, key) {
+ for (let value of array) {
+ map.set(value[key], value);
+ }
+ return map;
+}
+
function rootReducer(state = initialState, action) {
switch (action.type) {
case 'UPDATE_DEVICES':
return Object.assign({}, {
...state,
- devices: [...action.devices]
+ devices: updateMap(state.devices, action.devices, 'id')
});
case 'UPDATE_POSITIONS':
return Object.assign({}, {
...state,
- positions: [...action.positions]
+ positions: updateMap(state.positions, action.positions, 'deviceId')
});
default:
return state;