@etsoo/react 1.3.54 → 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.
@@ -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
  */
@@ -1,5 +1,4 @@
1
1
  import { CoreApp, createClient } from '@etsoo/appscript';
2
- import { Utils } from '@etsoo/shared';
3
2
  import React from 'react';
4
3
  import { NotifierMU } from '../mu/NotifierMU';
5
4
  import { ProgressCount } from '../mu/ProgressCount';
@@ -14,6 +13,7 @@ let globalApp;
14
13
  * Case 1: undefined, when refresh the whole page
15
14
  * Case 2: false, unauthorized
16
15
  * Case 3: true, authorized or considered as authorized (maynot, like token expiry)
16
+ * Case 4: property or properties changed
17
17
  * @param props Props
18
18
  * @returns Component
19
19
  */
@@ -24,24 +24,25 @@ export function ReactAppStateDetector(props) {
24
24
  const { state } = globalApp == null
25
25
  ? { state: {} }
26
26
  : React.useContext(globalApp.userState.context);
27
- // Match fields
28
- const changedFields = state.lastChangedFields;
29
- let matchedFields;
30
- if (targetFields == null || changedFields == null) {
31
- matchedFields = changedFields;
32
- }
33
- else {
34
- matchedFields = [];
35
- targetFields.forEach((targetField) => {
36
- if (changedFields.includes(targetField))
37
- matchedFields === null || matchedFields === void 0 ? void 0 : matchedFields.push(targetField);
38
- });
39
- }
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.authorized, matchedFields]);
45
+ }, [state]);
45
46
  // return
46
47
  return React.createElement(React.Fragment);
47
48
  }
@@ -211,15 +212,10 @@ export class ReactApp extends CoreApp {
211
212
  * @param keep Keep in local storage or not
212
213
  */
213
214
  userLogin(user, refreshToken, keep) {
214
- // Changed
215
- const dataChanged = !this.authorized ||
216
- this.userData == null ||
217
- !Utils.objectEqual(this.userData, user, ['seconds', 'token']);
218
215
  // Super call, set token
219
216
  super.userLogin(user, refreshToken, keep);
220
217
  // Dispatch action
221
- // Only when unauthorized or with changes except 'token' and 'seconds'
222
- if (this.userStateDispatch != null && dataChanged)
218
+ if (this.userStateDispatch != null)
223
219
  this.userStateDispatch({
224
220
  type: UserActionType.Login,
225
221
  user
@@ -67,7 +67,8 @@ export class UserState {
67
67
  this.provider = provider;
68
68
  }
69
69
  getChangedFields(input, init) {
70
- return Utils.getDataChanges(input, init, [
70
+ return Utils.objectUpdated(input, init, [
71
+ 'authorized',
71
72
  'seconds',
72
73
  'lastChangedFields'
73
74
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.3.54",
3
+ "version": "1.3.58",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -52,7 +52,7 @@
52
52
  "@emotion/styled": "^11.6.0",
53
53
  "@etsoo/appscript": "^1.1.79",
54
54
  "@etsoo/notificationbase": "^1.0.94",
55
- "@etsoo/shared": "^1.0.76",
55
+ "@etsoo/shared": "^1.0.78",
56
56
  "@mui/icons-material": "^5.2.4",
57
57
  "@mui/material": "^5.2.4",
58
58
  "@reach/router": "^1.3.4",
@@ -7,7 +7,7 @@ import {
7
7
  IUserData
8
8
  } from '@etsoo/appscript';
9
9
  import { NotificationRenderProps } from '@etsoo/notificationbase';
10
- import { DataTypes, Utils } from '@etsoo/shared';
10
+ import { DataTypes } from '@etsoo/shared';
11
11
  import React from 'react';
12
12
  import { NotifierMU } from '../mu/NotifierMU';
13
13
  import { ProgressCount } from '../mu/ProgressCount';
@@ -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,24 +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
56
  // Ready
69
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
+
70
78
  // Callback
71
79
  update(state.authorized, matchedFields);
72
- }, [state.authorized, matchedFields]);
80
+ }, [state]);
73
81
 
74
82
  // return
75
83
  return React.createElement(React.Fragment);
@@ -356,18 +364,11 @@ export class ReactApp<
356
364
  refreshToken: string,
357
365
  keep?: boolean
358
366
  ): void {
359
- // Changed
360
- const dataChanged =
361
- !this.authorized ||
362
- this.userData == null ||
363
- !Utils.objectEqual(this.userData, user, ['seconds', 'token']);
364
-
365
367
  // Super call, set token
366
368
  super.userLogin(user, refreshToken, keep);
367
369
 
368
370
  // Dispatch action
369
- // Only when unauthorized or with changes except 'token' and 'seconds'
370
- if (this.userStateDispatch != null && dataChanged)
371
+ if (this.userStateDispatch != null)
371
372
  this.userStateDispatch({
372
373
  type: UserActionType.Login,
373
374
  user
@@ -123,7 +123,8 @@ export class UserState<D extends IUser> {
123
123
  }
124
124
 
125
125
  private getChangedFields(input: {}, init: {}) {
126
- return Utils.getDataChanges(input, init, [
126
+ return Utils.objectUpdated(input, init, [
127
+ 'authorized',
127
128
  'seconds',
128
129
  'lastChangedFields'
129
130
  ]);