@zauru-sdk/redux 6.3.4 → 6.5.0

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 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.store = exports.cleanLocalStorage = exports.LOCAL_STORAGE_REDUX_NAME = void 0;
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"));
@@ -29,7 +29,7 @@ const formValidation_slice_js_1 = __importDefault(require("./slices/formValidati
29
29
  * private mode, Safari, or nearly full disks can lower the effective cap. Other
30
30
  * apps on the same origin share the same quota.
31
31
  */
32
- exports.LOCAL_STORAGE_REDUX_NAME = "___redux__state__v7.0";
32
+ exports.LOCAL_STORAGE_REDUX_NAME = "___redux__state__v8.0";
33
33
  function isQuotaExceededError(error) {
34
34
  if (error instanceof DOMException && error.name === "QuotaExceededError") {
35
35
  return true;
@@ -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") && Object.keys(state)?.length > 0) {
163
+ if (!(typeof document === "undefined")) {
140
164
  const initialState = buildSliceInitialStates();
141
165
  const newState = { ...initialState };
142
- for (const reducerName in whitelist) {
143
- if (state.hasOwnProperty(reducerName)) {
144
- const key = reducerName;
145
- const reducerState = state[key];
146
- const whitelistKey = whitelist[key];
147
- if (whitelistKey && whitelistKey.length > 0) {
148
- newState[key] = newState[key] ? { ...newState[key] } : {};
149
- for (const propertyName of whitelistKey) {
150
- if (reducerState?.hasOwnProperty(propertyName)) {
151
- const propKey = propertyName;
152
- if (newState[key] && reducerState) {
153
- newState[key][propKey] = reducerState[propKey];
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
- else if (reducerState) {
159
- newState[key] = reducerState;
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
@@ -13,14 +14,14 @@ import { Tuple } from "@reduxjs/toolkit";
13
14
  * private mode, Safari, or nearly full disks can lower the effective cap. Other
14
15
  * apps on the same origin share the same quota.
15
16
  */
16
- export declare const LOCAL_STORAGE_REDUX_NAME = "___redux__state__v7.0";
17
+ 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 cleanLocalStorage: (whitelist?: Whitelist) => void;
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.4",
3
+ "version": "6.5.0",
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",
@@ -32,5 +32,5 @@
32
32
  "react-redux": "^9.1.0",
33
33
  "react-select": "^5.8.0"
34
34
  },
35
- "gitHead": "2950c31a115494a2beefde49d411be7983d57982"
35
+ "gitHead": "4582fe6280d32113461687a5e1b23419be343798"
36
36
  }