@zauru-sdk/redux 2.31.1 → 2.32.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/slices/catalogs.slice.js +16 -5
- package/dist/esm/store.js +32 -12
- package/package.json +3 -3
|
@@ -59,20 +59,31 @@ const initialState = {
|
|
|
59
59
|
invoiceFormSubmissionsByAgencyId: createLoadingState([]),
|
|
60
60
|
caseFormSubmissionsByCaseId: createLoadingState([]),
|
|
61
61
|
};
|
|
62
|
+
const ensureCatalogEntry = (state, name) => {
|
|
63
|
+
if (!state[name]) {
|
|
64
|
+
state[name] = {
|
|
65
|
+
data: [],
|
|
66
|
+
loading: false,
|
|
67
|
+
reFetch: false,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return state[name];
|
|
71
|
+
};
|
|
62
72
|
const catalogsSlice = (0, toolkit_1.createSlice)({
|
|
63
73
|
name: "catalogs",
|
|
64
74
|
initialState,
|
|
65
75
|
reducers: {
|
|
66
76
|
catalogsSetReFetch: (state, action) => {
|
|
67
|
-
state
|
|
77
|
+
ensureCatalogEntry(state, action.payload).reFetch = true;
|
|
68
78
|
},
|
|
69
79
|
catalogsFetchStart: (state, action) => {
|
|
70
|
-
state
|
|
80
|
+
ensureCatalogEntry(state, action.payload).loading = true;
|
|
71
81
|
},
|
|
72
82
|
catalogsFetchSuccess: (state, action) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
const entry = ensureCatalogEntry(state, action.payload.name);
|
|
84
|
+
entry.data = action.payload.data;
|
|
85
|
+
entry.loading = false;
|
|
86
|
+
entry.reFetch = false;
|
|
76
87
|
},
|
|
77
88
|
},
|
|
78
89
|
});
|
package/dist/esm/store.js
CHANGED
|
@@ -23,12 +23,42 @@ const persistanceLocalStorageMiddleware = (store) => (next) => (action) => {
|
|
|
23
23
|
}
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
|
+
const buildSliceInitialStates = () => ({
|
|
27
|
+
catalogs: (0, catalogs_slice_js_1.default)(undefined, { type: "@@INIT" }),
|
|
28
|
+
profiles: (0, profile_slice_js_1.default)(undefined, { type: "@@INIT" }),
|
|
29
|
+
webappTables: (0, webapp_tables_slice_js_1.default)(undefined, { type: "@@INIT" }),
|
|
30
|
+
receptions: (0, reception_slice_js_1.default)(undefined, { type: "@@INIT" }),
|
|
31
|
+
session: (0, session_slice_js_1.default)(undefined, { type: "@@INIT" }),
|
|
32
|
+
templates: (0, templates_slice_js_1.default)(undefined, { type: "@@INIT" }),
|
|
33
|
+
automaticNumbers: (0, automaticNumbers_slice_js_1.default)(undefined, { type: "@@INIT" }),
|
|
34
|
+
tables: (0, tables_slice_js_1.default)(undefined, { type: "@@INIT" }),
|
|
35
|
+
formSavedData: (0, formsSavedData_slice_js_1.default)(undefined, { type: "@@INIT" }),
|
|
36
|
+
});
|
|
37
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26
38
|
const preloadedState = (() => {
|
|
27
39
|
try {
|
|
28
40
|
if (!(typeof document === "undefined")) {
|
|
29
41
|
const savedState = localStorage.getItem(exports.LOCAL_STORAGE_REDUX_NAME);
|
|
30
42
|
if (savedState) {
|
|
31
|
-
|
|
43
|
+
const parsed = JSON.parse(savedState);
|
|
44
|
+
// Merge each slice's defaults with the persisted state so that catalogs
|
|
45
|
+
// (or other entries) added in newer versions of the app are not missing
|
|
46
|
+
// when the user has an older snapshot in localStorage. Without this
|
|
47
|
+
// merge, `state.catalogs[NEW_CATALOG]` would be undefined and any
|
|
48
|
+
// reducer that mutates it (e.g. catalogsFetchStart) would throw.
|
|
49
|
+
const initialStates = buildSliceInitialStates();
|
|
50
|
+
const merged = {};
|
|
51
|
+
for (const sliceName of Object.keys(initialStates)) {
|
|
52
|
+
const sliceInitial = initialStates[sliceName];
|
|
53
|
+
const persistedSlice = parsed?.[sliceName];
|
|
54
|
+
if (isPlainObject(sliceInitial) && isPlainObject(persistedSlice)) {
|
|
55
|
+
merged[sliceName] = { ...sliceInitial, ...persistedSlice };
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
merged[sliceName] = persistedSlice ?? sliceInitial;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return merged;
|
|
32
62
|
}
|
|
33
63
|
}
|
|
34
64
|
}
|
|
@@ -70,17 +100,7 @@ const cleanLocalStorage = (whitelist = {}) => {
|
|
|
70
100
|
}
|
|
71
101
|
try {
|
|
72
102
|
if (!(typeof document === "undefined") && Object.keys(state)?.length > 0) {
|
|
73
|
-
const initialState =
|
|
74
|
-
catalogs: (0, catalogs_slice_js_1.default)(undefined, { type: "" }),
|
|
75
|
-
profiles: (0, profile_slice_js_1.default)(undefined, { type: "" }),
|
|
76
|
-
webappTables: (0, webapp_tables_slice_js_1.default)(undefined, { type: "" }),
|
|
77
|
-
receptions: (0, reception_slice_js_1.default)(undefined, { type: "" }),
|
|
78
|
-
session: (0, session_slice_js_1.default)(undefined, { type: "" }),
|
|
79
|
-
templates: (0, templates_slice_js_1.default)(undefined, { type: "" }),
|
|
80
|
-
automaticNumbers: (0, automaticNumbers_slice_js_1.default)(undefined, { type: "" }),
|
|
81
|
-
tables: (0, tables_slice_js_1.default)(undefined, { type: "" }),
|
|
82
|
-
formSavedData: (0, formsSavedData_slice_js_1.default)(undefined, { type: "" }),
|
|
83
|
-
};
|
|
103
|
+
const initialState = buildSliceInitialStates();
|
|
84
104
|
const newState = { ...initialState };
|
|
85
105
|
for (const reducerName in whitelist) {
|
|
86
106
|
if (state.hasOwnProperty(reducerName)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/redux",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.32.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",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@reduxjs/toolkit": "^2.2.1",
|
|
28
|
-
"@zauru-sdk/types": "^2.
|
|
28
|
+
"@zauru-sdk/types": "^2.32.0",
|
|
29
29
|
"react": "^18.2.0",
|
|
30
30
|
"react-dom": "^18.2.0",
|
|
31
31
|
"react-redux": "^9.1.0",
|
|
32
32
|
"react-select": "^5.8.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "1e4fc27b09241e4cf9bbc03d1e8d8d26be04cc1a"
|
|
35
35
|
}
|