@etsoo/react 1.3.57 → 1.3.58
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/lib/app/ReactApp.d.ts +1 -0
- package/lib/app/ReactApp.js +16 -15
- package/lib/states/UserState.js +1 -0
- package/package.json +1 -1
- package/src/app/ReactApp.ts +22 -16
- package/src/states/UserState.ts +1 -0
package/lib/app/ReactApp.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { InputDialogProps } from './InputDialogProps';
|
|
|
13
13
|
* Case 1: undefined, when refresh the whole page
|
|
14
14
|
* Case 2: false, unauthorized
|
|
15
15
|
* Case 3: true, authorized or considered as authorized (maynot, like token expiry)
|
|
16
|
+
* Case 4: property or properties changed
|
|
16
17
|
* @param props Props
|
|
17
18
|
* @returns Component
|
|
18
19
|
*/
|
package/lib/app/ReactApp.js
CHANGED
|
@@ -13,6 +13,7 @@ let globalApp;
|
|
|
13
13
|
* Case 1: undefined, when refresh the whole page
|
|
14
14
|
* Case 2: false, unauthorized
|
|
15
15
|
* Case 3: true, authorized or considered as authorized (maynot, like token expiry)
|
|
16
|
+
* Case 4: property or properties changed
|
|
16
17
|
* @param props Props
|
|
17
18
|
* @returns Component
|
|
18
19
|
*/
|
|
@@ -23,25 +24,25 @@ export function ReactAppStateDetector(props) {
|
|
|
23
24
|
const { state } = globalApp == null
|
|
24
25
|
? { state: {} }
|
|
25
26
|
: React.useContext(globalApp.userState.context);
|
|
26
|
-
// Match fields
|
|
27
|
-
const changedFields = state.lastChangedFields;
|
|
28
|
-
let matchedFields;
|
|
29
|
-
if (targetFields == null || changedFields == null) {
|
|
30
|
-
matchedFields = changedFields;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
matchedFields = [];
|
|
34
|
-
targetFields.forEach((targetField) => {
|
|
35
|
-
if (changedFields.includes(targetField))
|
|
36
|
-
matchedFields === null || matchedFields === void 0 ? void 0 : matchedFields.push(targetField);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
console.log(targetFields, changedFields, matchedFields);
|
|
40
27
|
// Ready
|
|
41
28
|
React.useEffect(() => {
|
|
29
|
+
// Match fields
|
|
30
|
+
const changedFields = state.lastChangedFields;
|
|
31
|
+
let matchedFields;
|
|
32
|
+
if (targetFields == null || changedFields == null) {
|
|
33
|
+
matchedFields = changedFields;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
matchedFields = [];
|
|
37
|
+
targetFields.forEach((targetField) => {
|
|
38
|
+
if (changedFields.includes(targetField))
|
|
39
|
+
matchedFields === null || matchedFields === void 0 ? void 0 : matchedFields.push(targetField);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
console.log('ReactAppStateDetector', changedFields, targetFields, matchedFields);
|
|
42
43
|
// Callback
|
|
43
44
|
update(state.authorized, matchedFields);
|
|
44
|
-
}, [state
|
|
45
|
+
}, [state]);
|
|
45
46
|
// return
|
|
46
47
|
return React.createElement(React.Fragment);
|
|
47
48
|
}
|
package/lib/states/UserState.js
CHANGED
package/package.json
CHANGED
package/src/app/ReactApp.ts
CHANGED
|
@@ -37,6 +37,7 @@ let globalApp: IReactApp<IAppSettings, any, IPageData>;
|
|
|
37
37
|
* Case 1: undefined, when refresh the whole page
|
|
38
38
|
* Case 2: false, unauthorized
|
|
39
39
|
* Case 3: true, authorized or considered as authorized (maynot, like token expiry)
|
|
40
|
+
* Case 4: property or properties changed
|
|
40
41
|
* @param props Props
|
|
41
42
|
* @returns Component
|
|
42
43
|
*/
|
|
@@ -52,26 +53,31 @@ export function ReactAppStateDetector(props: IStateProps) {
|
|
|
52
53
|
(globalApp.userState as UserState<IUser>).context
|
|
53
54
|
);
|
|
54
55
|
|
|
55
|
-
// Match fields
|
|
56
|
-
const changedFields = state.lastChangedFields;
|
|
57
|
-
let matchedFields: string[] | undefined;
|
|
58
|
-
if (targetFields == null || changedFields == null) {
|
|
59
|
-
matchedFields = changedFields;
|
|
60
|
-
} else {
|
|
61
|
-
matchedFields = [];
|
|
62
|
-
targetFields.forEach((targetField) => {
|
|
63
|
-
if (changedFields.includes(targetField))
|
|
64
|
-
matchedFields?.push(targetField);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
console.log(targetFields, changedFields, matchedFields);
|
|
69
|
-
|
|
70
56
|
// Ready
|
|
71
57
|
React.useEffect(() => {
|
|
58
|
+
// Match fields
|
|
59
|
+
const changedFields = state.lastChangedFields;
|
|
60
|
+
let matchedFields: string[] | undefined;
|
|
61
|
+
if (targetFields == null || changedFields == null) {
|
|
62
|
+
matchedFields = changedFields;
|
|
63
|
+
} else {
|
|
64
|
+
matchedFields = [];
|
|
65
|
+
targetFields.forEach((targetField) => {
|
|
66
|
+
if (changedFields.includes(targetField))
|
|
67
|
+
matchedFields?.push(targetField);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
console.log(
|
|
72
|
+
'ReactAppStateDetector',
|
|
73
|
+
changedFields,
|
|
74
|
+
targetFields,
|
|
75
|
+
matchedFields
|
|
76
|
+
);
|
|
77
|
+
|
|
72
78
|
// Callback
|
|
73
79
|
update(state.authorized, matchedFields);
|
|
74
|
-
}, [state
|
|
80
|
+
}, [state]);
|
|
75
81
|
|
|
76
82
|
// return
|
|
77
83
|
return React.createElement(React.Fragment);
|