diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-03-25 00:31:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-25 00:31:37 -0700 |
commit | b10607f96ad72f5f971fbd867eeeeb86380f79cb (patch) | |
tree | 81b7a13c0c3fc4da12182ee20518f021406def9b /modern/src/store | |
parent | 78d69f50595e058a08f3eaaa47fd7c3745fa1266 (diff) | |
parent | 37f8b1cd81614ed9281647b326a30d58123c5942 (diff) | |
download | trackermap-web-b10607f96ad72f5f971fbd867eeeeb86380f79cb.tar.gz trackermap-web-b10607f96ad72f5f971fbd867eeeeb86380f79cb.tar.bz2 trackermap-web-b10607f96ad72f5f971fbd867eeeeb86380f79cb.zip |
Merge pull request #772 from dt-ap/experiment/redux-toolkit
Experimental: Use Redux Toolkit
Diffstat (limited to 'modern/src/store')
-rw-r--r-- | modern/src/store/devices.js | 20 | ||||
-rw-r--r-- | modern/src/store/index.js | 14 | ||||
-rw-r--r-- | modern/src/store/positions.js | 16 |
3 files changed, 50 insertions, 0 deletions
diff --git a/modern/src/store/devices.js b/modern/src/store/devices.js new file mode 100644 index 00000000..0d96e98d --- /dev/null +++ b/modern/src/store/devices.js @@ -0,0 +1,20 @@ +import { createSlice } from '@reduxjs/toolkit'; + +const { reducer, actions } = createSlice({ + name: 'devices', + initialState: { + items: {}, + selectedId: null + }, + reducers: { + update(state, action) { + action.payload.forEach(item => state.items[item['id']] = item); + }, + select(state, action) { + state.selectedId = action.payload.id; + } + } +}); + +export { actions as devicesActions }; +export { reducer as devicesReducer }; diff --git a/modern/src/store/index.js b/modern/src/store/index.js new file mode 100644 index 00000000..86de31a9 --- /dev/null +++ b/modern/src/store/index.js @@ -0,0 +1,14 @@ +import { combineReducers, configureStore } from '@reduxjs/toolkit'; + +import { devicesReducer as devices } from './devices'; +import { positionsReducer as positions } from './positions'; + +const reducer = combineReducers({ + devices, + positions, +}); + +export { devicesActions } from './devices'; +export { positionsActions } from './positions'; + +export default configureStore({ reducer }); diff --git a/modern/src/store/positions.js b/modern/src/store/positions.js new file mode 100644 index 00000000..1df468cd --- /dev/null +++ b/modern/src/store/positions.js @@ -0,0 +1,16 @@ +import { createSlice } from '@reduxjs/toolkit'; + +const { reducer, actions } = createSlice({ + name: 'positions', + initialState: { + items: {}, + }, + reducers: { + update(state, action) { + action.payload.forEach(item => state.items[item['deviceId']] = item); + }, + } +}); + +export { actions as positionsActions }; +export { reducer as positionsReducer }; |