diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-03-22 23:07:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-22 23:07:16 -0700 |
commit | 48a726021f5d3c741749094891d529ccb3ba59b4 (patch) | |
tree | 8df80eca54f9dd39664f63365ffcc2ec248fb3df /modern/src/reducers | |
parent | f5165c8e897e8d9cf4219d943e2d34b61adb48b5 (diff) | |
parent | ba9cc86f667486a09edb323402c2d63ada5ea639 (diff) | |
download | trackermap-web-48a726021f5d3c741749094891d529ccb3ba59b4.tar.gz trackermap-web-48a726021f5d3c741749094891d529ccb3ba59b4.tar.bz2 trackermap-web-48a726021f5d3c741749094891d529ccb3ba59b4.zip |
Merge pull request #768 from traccar/modern
Create a new React web app
Diffstat (limited to 'modern/src/reducers')
-rw-r--r-- | modern/src/reducers/index.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/modern/src/reducers/index.js b/modern/src/reducers/index.js new file mode 100644 index 00000000..752a4c3f --- /dev/null +++ b/modern/src/reducers/index.js @@ -0,0 +1,35 @@ +const initialState = { + 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: updateMap(state.devices, action.devices, 'id') + }); + case 'UPDATE_POSITIONS': + return Object.assign({}, { + ...state, + positions: updateMap(state.positions, action.positions, 'deviceId') + }); + case 'SELECT_DEVICE': + return Object.assign({}, { + ...state, + selectedDevice: action.device.id + }); + default: + return state; + } +} + +export default rootReducer |