aboutsummaryrefslogtreecommitdiff
path: root/modern/src/store
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/store')
-rw-r--r--modern/src/store/devices.js20
-rw-r--r--modern/src/store/index.js14
-rw-r--r--modern/src/store/positions.js16
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 };