diff options
Diffstat (limited to 'modern/src/store')
-rw-r--r-- | modern/src/store/index.js | 5 | ||||
-rw-r--r-- | modern/src/store/modules/devices.js | 20 | ||||
-rw-r--r-- | modern/src/store/modules/index.js | 12 | ||||
-rw-r--r-- | modern/src/store/modules/positions.js | 16 |
4 files changed, 53 insertions, 0 deletions
diff --git a/modern/src/store/index.js b/modern/src/store/index.js new file mode 100644 index 00000000..c981c136 --- /dev/null +++ b/modern/src/store/index.js @@ -0,0 +1,5 @@ +import { configureStore } from '@reduxjs/toolkit'; + +import { rootReducer } from './modules'; + +export default configureStore({ reducer: rootReducer }); diff --git a/modern/src/store/modules/devices.js b/modern/src/store/modules/devices.js new file mode 100644 index 00000000..0d96e98d --- /dev/null +++ b/modern/src/store/modules/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/modules/index.js b/modern/src/store/modules/index.js new file mode 100644 index 00000000..e2037c72 --- /dev/null +++ b/modern/src/store/modules/index.js @@ -0,0 +1,12 @@ +import { combineReducers } from '@reduxjs/toolkit'; + +import { devicesReducer as devices } from './devices'; +import { positionsReducer as positions } from './positions'; + +export const rootReducer = combineReducers({ + devices, + positions, +}); + +export { devicesActions } from './devices'; +export { positionsActions } from './positions'; diff --git a/modern/src/store/modules/positions.js b/modern/src/store/modules/positions.js new file mode 100644 index 00000000..1df468cd --- /dev/null +++ b/modern/src/store/modules/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 }; |