@zauru-sdk/redux 6.4.0 → 6.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/store.js +47 -34
- package/dist/store.d.ts +3 -2
- package/package.json +3 -3
package/dist/esm/store.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useAppDispatch = exports.useAppSelector = exports.
|
|
6
|
+
exports.useAppDispatch = exports.useAppSelector = exports.cleanLocalStorage = exports.store = exports.LOCAL_STORAGE_REDUX_NAME = void 0;
|
|
7
7
|
const react_redux_1 = require("react-redux");
|
|
8
8
|
const toolkit_1 = require("@reduxjs/toolkit");
|
|
9
9
|
const catalogs_slice_js_1 = __importDefault(require("./slices/catalogs.slice.js"));
|
|
@@ -103,6 +103,30 @@ const preloadedState = (() => {
|
|
|
103
103
|
// Ignorar los errores, se utiliza el estado inicial definido en cada reducer
|
|
104
104
|
}
|
|
105
105
|
})();
|
|
106
|
+
const RESET_STORE = "zauru/RESET_STORE";
|
|
107
|
+
const appReducer = (0, toolkit_1.combineReducers)({
|
|
108
|
+
catalogs: catalogs_slice_js_1.default,
|
|
109
|
+
profiles: profile_slice_js_1.default,
|
|
110
|
+
webappTables: webapp_tables_slice_js_1.default,
|
|
111
|
+
receptions: reception_slice_js_1.default,
|
|
112
|
+
session: session_slice_js_1.default,
|
|
113
|
+
templates: templates_slice_js_1.default,
|
|
114
|
+
automaticNumbers: automaticNumbers_slice_js_1.default,
|
|
115
|
+
tables: tables_slice_js_1.default,
|
|
116
|
+
formSavedData: formsSavedData_slice_js_1.default,
|
|
117
|
+
formValidation: formValidation_slice_js_1.default,
|
|
118
|
+
});
|
|
119
|
+
const rootReducer = (state, action) => {
|
|
120
|
+
if (action.type === RESET_STORE) {
|
|
121
|
+
return action.payload;
|
|
122
|
+
}
|
|
123
|
+
return appReducer(state, action);
|
|
124
|
+
};
|
|
125
|
+
exports.store = (0, toolkit_1.configureStore)({
|
|
126
|
+
reducer: rootReducer,
|
|
127
|
+
preloadedState,
|
|
128
|
+
middleware: (getDefaultMiddleware) => new toolkit_1.Tuple(persistanceLocalStorageMiddleware),
|
|
129
|
+
});
|
|
106
130
|
const cleanLocalStorage = (whitelist = {}) => {
|
|
107
131
|
const savedState = localStorage.getItem(exports.LOCAL_STORAGE_REDUX_NAME);
|
|
108
132
|
const state = JSON.parse(savedState ?? "{}");
|
|
@@ -136,32 +160,37 @@ const cleanLocalStorage = (whitelist = {}) => {
|
|
|
136
160
|
console.error(error);
|
|
137
161
|
}
|
|
138
162
|
try {
|
|
139
|
-
if (!(typeof document === "undefined")
|
|
163
|
+
if (!(typeof document === "undefined")) {
|
|
140
164
|
const initialState = buildSliceInitialStates();
|
|
141
165
|
const newState = { ...initialState };
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
166
|
+
if (Object.keys(state)?.length > 0) {
|
|
167
|
+
const stateRecord = state;
|
|
168
|
+
const nextState = newState;
|
|
169
|
+
const whitelistRecord = whitelist;
|
|
170
|
+
for (const reducerName in whitelist) {
|
|
171
|
+
if (Object.prototype.hasOwnProperty.call(stateRecord, reducerName)) {
|
|
172
|
+
const reducerState = stateRecord[reducerName];
|
|
173
|
+
const whitelistKey = whitelistRecord[reducerName];
|
|
174
|
+
if (whitelistKey && whitelistKey.length > 0) {
|
|
175
|
+
nextState[reducerName] = nextState[reducerName]
|
|
176
|
+
? { ...nextState[reducerName] }
|
|
177
|
+
: {};
|
|
178
|
+
for (const propertyName of whitelistKey) {
|
|
179
|
+
if (reducerState &&
|
|
180
|
+
Object.prototype.hasOwnProperty.call(reducerState, propertyName)) {
|
|
181
|
+
nextState[reducerName][propertyName] =
|
|
182
|
+
reducerState[propertyName];
|
|
154
183
|
}
|
|
155
184
|
}
|
|
156
185
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
186
|
+
else if (reducerState) {
|
|
187
|
+
nextState[reducerName] = reducerState;
|
|
188
|
+
}
|
|
160
189
|
}
|
|
161
190
|
}
|
|
162
191
|
}
|
|
163
|
-
// Guarda el nuevo estado en el almacenamiento local
|
|
164
192
|
persistReduxStateToLocalStorage(newState);
|
|
193
|
+
exports.store.dispatch({ type: RESET_STORE, payload: newState });
|
|
165
194
|
}
|
|
166
195
|
}
|
|
167
196
|
catch (e) {
|
|
@@ -174,21 +203,5 @@ const cleanLocalStorage = (whitelist = {}) => {
|
|
|
174
203
|
}
|
|
175
204
|
};
|
|
176
205
|
exports.cleanLocalStorage = cleanLocalStorage;
|
|
177
|
-
exports.store = (0, toolkit_1.configureStore)({
|
|
178
|
-
reducer: {
|
|
179
|
-
catalogs: catalogs_slice_js_1.default,
|
|
180
|
-
profiles: profile_slice_js_1.default,
|
|
181
|
-
webappTables: webapp_tables_slice_js_1.default,
|
|
182
|
-
receptions: reception_slice_js_1.default,
|
|
183
|
-
session: session_slice_js_1.default,
|
|
184
|
-
templates: templates_slice_js_1.default,
|
|
185
|
-
automaticNumbers: automaticNumbers_slice_js_1.default,
|
|
186
|
-
tables: tables_slice_js_1.default,
|
|
187
|
-
formSavedData: formsSavedData_slice_js_1.default,
|
|
188
|
-
formValidation: formValidation_slice_js_1.default,
|
|
189
|
-
},
|
|
190
|
-
preloadedState,
|
|
191
|
-
middleware: (getDefaultMiddleware) => new toolkit_1.Tuple(persistanceLocalStorageMiddleware),
|
|
192
|
-
});
|
|
193
206
|
exports.useAppSelector = react_redux_1.useSelector;
|
|
194
207
|
exports.useAppDispatch = react_redux_1.useDispatch;
|
package/dist/store.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TypedUseSelectorHook } from "react-redux";
|
|
2
|
+
import type { AnyAction } from "@reduxjs/toolkit";
|
|
2
3
|
import { Tuple } from "@reduxjs/toolkit";
|
|
3
4
|
/**
|
|
4
5
|
* Full Redux snapshot key in `localStorage`. Written by
|
|
@@ -17,10 +18,10 @@ export declare const LOCAL_STORAGE_REDUX_NAME = "___redux__state__v8.0";
|
|
|
17
18
|
type Whitelist = {
|
|
18
19
|
[K in keyof RootState]?: string[];
|
|
19
20
|
};
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const store: import("@reduxjs/toolkit").EnhancedStore<any, import("@reduxjs/toolkit").UnknownAction, Tuple<[import("@reduxjs/toolkit").StoreEnhancer<{
|
|
21
|
+
export declare const store: import("@reduxjs/toolkit").EnhancedStore<any, AnyAction, Tuple<[import("@reduxjs/toolkit").StoreEnhancer<{
|
|
22
22
|
dispatch: {};
|
|
23
23
|
}>, import("@reduxjs/toolkit").StoreEnhancer]>>;
|
|
24
|
+
export declare const cleanLocalStorage: (whitelist?: Whitelist) => void;
|
|
24
25
|
export type RootState = ReturnType<typeof store.getState>;
|
|
25
26
|
export type AppDispatch = typeof store.dispatch;
|
|
26
27
|
export declare const useAppSelector: TypedUseSelectorHook<RootState>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/redux",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.1",
|
|
4
4
|
"description": "Estructura de Redux propuesta para el desarrollo de webapps en Zauru.",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@reduxjs/toolkit": "^2.2.1",
|
|
29
|
-
"@zauru-sdk/types": "^6.
|
|
29
|
+
"@zauru-sdk/types": "^6.8.0",
|
|
30
30
|
"react": "^18.2.0",
|
|
31
31
|
"react-dom": "^18.2.0",
|
|
32
32
|
"react-redux": "^9.1.0",
|
|
33
33
|
"react-select": "^5.8.0"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "0b76f82d8d5169437231694b666c29ce50a37a77"
|
|
36
36
|
}
|