aboutsummaryrefslogtreecommitdiff
path: root/modern/src/reducers
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-03-22 17:32:36 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-03-22 17:32:36 -0700
commit00daddce89f70989baecd8725e6df9bc88257b53 (patch)
treeabe4d199f269bb925831421fab17f5141f2640c3 /modern/src/reducers
parent5e98816922c284805714e35a678f1a7dfa3facb8 (diff)
downloadetbsa-traccar-web-00daddce89f70989baecd8725e6df9bc88257b53.tar.gz
etbsa-traccar-web-00daddce89f70989baecd8725e6df9bc88257b53.tar.bz2
etbsa-traccar-web-00daddce89f70989baecd8725e6df9bc88257b53.zip
Display features
Diffstat (limited to 'modern/src/reducers')
-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;