redux, redux-toolkit, react-rrdux

This commit is contained in:
ISA
2024-11-01 06:30:33 +01:00
parent f2143daa51
commit 9c21cd271c
5 changed files with 193 additions and 24 deletions

11
store/store.js Normal file
View File

@@ -0,0 +1,11 @@
// store/store.js
import { configureStore } from "@reduxjs/toolkit";
import variablesReducer from "./variablesSlice";
const store = configureStore({
reducer: {
variables: variablesReducer,
},
});
export default store;

58
store/variablesSlice.js Normal file
View File

@@ -0,0 +1,58 @@
// store/variablesSlice.js
import { createSlice } from "@reduxjs/toolkit";
const initialState = {
last20Messages: null,
deviceName: null,
mac1: null,
mac2: null,
ip: null,
subnet: null,
gateway: null,
datetime: null,
de: null,
counter: null,
flutter: null,
kueOnline: [],
kueID: [],
kueAlarm1: [],
kueAlarm2: [],
kueRes: [],
kueCableBreak: [],
kueGroundFault: [],
kueLimit1: null,
kueLimit2Low: null,
kueDelay1: null,
kueLoopInterval: null,
kueVersion: null,
tdrAtten: null,
tdrPulse: null,
tdrSpeed: null,
tdrAmp: null,
tdrTrigger: null,
tdrLocation: null,
tdrActive: null,
kueOverflow: null,
kueResidence: null,
tdrLast: null,
appVersion: null,
};
const variablesSlice = createSlice({
name: "variables",
initialState,
reducers: {
setVariable(state, action) {
const { key, value } = action.payload;
state[key] = value;
},
setVariables(state, action) {
Object.entries(action.payload).forEach(([key, value]) => {
state[key] = value;
});
},
},
});
export const { setVariable, setVariables } = variablesSlice.actions;
export default variablesSlice.reducer;