@trackunit/react-core-contexts-test 0.1.194 → 0.1.196

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 @@ require('@trackunit/react-core-contexts-api');
13
13
  require('@apollo/client/react');
14
14
  require('@tanstack/react-router');
15
15
  require('react');
16
+ require('@trackunit/shared-utils');
16
17
  require('graphql');
17
18
 
18
19
  /**
@@ -11,6 +11,7 @@ import '@trackunit/react-core-contexts-api';
11
11
  import '@apollo/client/react';
12
12
  import '@tanstack/react-router';
13
13
  import 'react';
14
+ import '@trackunit/shared-utils';
14
15
  import 'graphql';
15
16
 
16
17
  /**
package/index.cjs.js CHANGED
@@ -14,6 +14,7 @@ require('@trackunit/react-core-contexts-api');
14
14
  require('@apollo/client/react');
15
15
  require('@tanstack/react-router');
16
16
  require('react');
17
+ require('@trackunit/shared-utils');
17
18
  require('graphql');
18
19
 
19
20
 
@@ -34,4 +35,5 @@ exports.queryFor = index.queryFor;
34
35
  exports.queryForHook = index.queryForHook;
35
36
  exports.trackunitProviders = index.trackunitProviders;
36
37
  exports.useDebugger = index.useDebugger;
38
+ exports.useIsFirstRender = index.useIsFirstRender;
37
39
  exports.validateIrisApp = index.validateIrisApp;
package/index.cjs2.js CHANGED
@@ -11,6 +11,7 @@ var reactCoreContextsApi = require('@trackunit/react-core-contexts-api');
11
11
  var react = require('@apollo/client/react');
12
12
  var reactRouter = require('@tanstack/react-router');
13
13
  var React = require('react');
14
+ var sharedUtils = require('@trackunit/shared-utils');
14
15
  var graphql = require('graphql');
15
16
 
16
17
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -846,6 +847,19 @@ class TrackunitProvidersMockBuilder {
846
847
  */
847
848
  const trackunitProviders = () => new TrackunitProvidersMockBuilder();
848
849
 
850
+ /**
851
+ * Differentiate between the first and subsequent renders.
852
+ *
853
+ * @returns {boolean} Returns true if it is the first render, false otherwise.
854
+ */
855
+ const useIsFirstRender = () => {
856
+ const renderRef = React.useRef(true);
857
+ if (renderRef.current === true) {
858
+ renderRef.current = false;
859
+ return true;
860
+ }
861
+ return renderRef.current;
862
+ };
849
863
  /**
850
864
  * Logs props that have changed.
851
865
  * Use this for debugging which props force a component to re-render.
@@ -876,18 +890,20 @@ const useDebugger = (propsToWatch, id) => {
876
890
  }
877
891
  return stackId || "unknown-id";
878
892
  }, [id]);
893
+ const isFirstRender = useIsFirstRender();
879
894
  // eslint-disable-next-line no-console
880
- console.log("Rerender", uniqueId, window.location.pathname);
895
+ console.log(isFirstRender ? "First-render" : "Re-render", uniqueId, window.location.pathname);
881
896
  React.useEffect(() => {
897
+ // eslint-disable-next-line local-rules/prefer-custom-object-entries
882
898
  const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
883
899
  if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
884
900
  result[key + ""] = [prevPropsRef.current[key], value];
885
901
  }
886
902
  return result;
887
903
  }, {});
888
- if (Object.keys(changedProps).length > 0) {
904
+ if (sharedUtils.objectKeys(changedProps).length > 0) {
889
905
  // eslint-disable-next-line no-console
890
- Object.keys(changedProps).forEach(changedProp => {
906
+ sharedUtils.objectKeys(changedProps).forEach(changedProp => {
891
907
  // eslint-disable-next-line no-console
892
908
  console.log(`${uniqueId} changed property: ${changedProp}`);
893
909
  // JSON stringify is used to avoid console.table from logging the object reference
@@ -896,12 +912,12 @@ const useDebugger = (propsToWatch, id) => {
896
912
  const result1 = result[1];
897
913
  result0 &&
898
914
  typeof result0 === "object" &&
899
- Object.keys(result0).forEach(prop => {
915
+ sharedUtils.objectKeys(result0).forEach(prop => {
900
916
  result0[prop] = typeof result0[prop] === "object" ? JSON.stringify(result0[prop]) : result0[prop];
901
917
  });
902
918
  result1 &&
903
919
  typeof result1 === "object" &&
904
- Object.keys(result1).forEach(prop => {
920
+ sharedUtils.objectKeys(result1).forEach(prop => {
905
921
  result1[prop] = typeof result1[prop] === "object" ? JSON.stringify(result1[prop]) : result1[prop];
906
922
  });
907
923
  // eslint-disable-next-line no-console
@@ -1103,4 +1119,5 @@ exports.queryFor = queryFor;
1103
1119
  exports.queryForHook = queryForHook;
1104
1120
  exports.trackunitProviders = trackunitProviders;
1105
1121
  exports.useDebugger = useDebugger;
1122
+ exports.useIsFirstRender = useIsFirstRender;
1106
1123
  exports.validateIrisApp = validateIrisApp;
package/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- export { D as Debugger, T as TrackunitProvidersMockBuilder, h as doNothing, f as flushPromises, j as flushPromisesInAct, m as mockAnalyticsContext, a as mockAssetSortingContext, b as mockCurrentUserContext, c as mockEnvironmentContext, d as mockOemBrandingContext, e as mockToastContext, g as mockUserSubscriptionContext, q as queryFor, i as queryForHook, t as trackunitProviders, u as useDebugger, v as validateIrisApp } from './index.esm2.js';
1
+ export { D as Debugger, T as TrackunitProvidersMockBuilder, i as doNothing, f as flushPromises, k as flushPromisesInAct, m as mockAnalyticsContext, b as mockAssetSortingContext, c as mockCurrentUserContext, d as mockEnvironmentContext, e as mockOemBrandingContext, g as mockToastContext, h as mockUserSubscriptionContext, q as queryFor, j as queryForHook, t as trackunitProviders, a as useDebugger, u as useIsFirstRender, v as validateIrisApp } from './index.esm2.js';
2
2
  import 'react/jsx-runtime';
3
3
  import '@testing-library/react';
4
4
  import '@trackunit/react-core-hooks';
@@ -10,4 +10,5 @@ import '@trackunit/react-core-contexts-api';
10
10
  import '@apollo/client/react';
11
11
  import '@tanstack/react-router';
12
12
  import 'react';
13
+ import '@trackunit/shared-utils';
13
14
  import 'graphql';
package/index.esm2.js CHANGED
@@ -9,6 +9,7 @@ import { AssetSortByProperty, SortOrder } from '@trackunit/react-core-contexts-a
9
9
  import { useApolloClient } from '@apollo/client/react';
10
10
  import { createMemoryHistory, createRootRoute, createRoute, createLazyRoute, createRouter, RouterProvider, Outlet } from '@tanstack/react-router';
11
11
  import React, { useMemo, useCallback, useRef, useEffect } from 'react';
12
+ import { objectKeys } from '@trackunit/shared-utils';
12
13
  import { GraphQLError } from 'graphql';
13
14
 
14
15
  /******************************************************************************
@@ -839,6 +840,19 @@ class TrackunitProvidersMockBuilder {
839
840
  */
840
841
  const trackunitProviders = () => new TrackunitProvidersMockBuilder();
841
842
 
843
+ /**
844
+ * Differentiate between the first and subsequent renders.
845
+ *
846
+ * @returns {boolean} Returns true if it is the first render, false otherwise.
847
+ */
848
+ const useIsFirstRender = () => {
849
+ const renderRef = useRef(true);
850
+ if (renderRef.current === true) {
851
+ renderRef.current = false;
852
+ return true;
853
+ }
854
+ return renderRef.current;
855
+ };
842
856
  /**
843
857
  * Logs props that have changed.
844
858
  * Use this for debugging which props force a component to re-render.
@@ -869,18 +883,20 @@ const useDebugger = (propsToWatch, id) => {
869
883
  }
870
884
  return stackId || "unknown-id";
871
885
  }, [id]);
886
+ const isFirstRender = useIsFirstRender();
872
887
  // eslint-disable-next-line no-console
873
- console.log("Rerender", uniqueId, window.location.pathname);
888
+ console.log(isFirstRender ? "First-render" : "Re-render", uniqueId, window.location.pathname);
874
889
  useEffect(() => {
890
+ // eslint-disable-next-line local-rules/prefer-custom-object-entries
875
891
  const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
876
892
  if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
877
893
  result[key + ""] = [prevPropsRef.current[key], value];
878
894
  }
879
895
  return result;
880
896
  }, {});
881
- if (Object.keys(changedProps).length > 0) {
897
+ if (objectKeys(changedProps).length > 0) {
882
898
  // eslint-disable-next-line no-console
883
- Object.keys(changedProps).forEach(changedProp => {
899
+ objectKeys(changedProps).forEach(changedProp => {
884
900
  // eslint-disable-next-line no-console
885
901
  console.log(`${uniqueId} changed property: ${changedProp}`);
886
902
  // JSON stringify is used to avoid console.table from logging the object reference
@@ -889,12 +905,12 @@ const useDebugger = (propsToWatch, id) => {
889
905
  const result1 = result[1];
890
906
  result0 &&
891
907
  typeof result0 === "object" &&
892
- Object.keys(result0).forEach(prop => {
908
+ objectKeys(result0).forEach(prop => {
893
909
  result0[prop] = typeof result0[prop] === "object" ? JSON.stringify(result0[prop]) : result0[prop];
894
910
  });
895
911
  result1 &&
896
912
  typeof result1 === "object" &&
897
- Object.keys(result1).forEach(prop => {
913
+ objectKeys(result1).forEach(prop => {
898
914
  result1[prop] = typeof result1[prop] === "object" ? JSON.stringify(result1[prop]) : result1[prop];
899
915
  });
900
916
  // eslint-disable-next-line no-console
@@ -1079,4 +1095,4 @@ const validateIrisApp = (irisApp) => __awaiter(void 0, void 0, void 0, function*
1079
1095
  return null;
1080
1096
  });
1081
1097
 
1082
- export { Debugger as D, TrackunitProvidersMockBuilder as T, __awaiter as _, mockAssetSortingContext as a, mockCurrentUserContext as b, mockEnvironmentContext as c, mockOemBrandingContext as d, mockToastContext as e, flushPromises as f, mockUserSubscriptionContext as g, doNothing as h, queryForHook as i, flushPromisesInAct as j, mockAnalyticsContext as m, queryFor as q, trackunitProviders as t, useDebugger as u, validateIrisApp as v };
1098
+ export { Debugger as D, TrackunitProvidersMockBuilder as T, __awaiter as _, useDebugger as a, mockAssetSortingContext as b, mockCurrentUserContext as c, mockEnvironmentContext as d, mockOemBrandingContext as e, flushPromises as f, mockToastContext as g, mockUserSubscriptionContext as h, doNothing as i, queryForHook as j, flushPromisesInAct as k, mockAnalyticsContext as m, queryFor as q, trackunitProviders as t, useIsFirstRender as u, validateIrisApp as v };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts-test",
3
- "version": "0.1.194",
3
+ "version": "0.1.196",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -14,7 +14,8 @@
14
14
  "@trackunit/react-core-hooks": "*",
15
15
  "lodash": "4.17.21",
16
16
  "graphql": "^15.8.0",
17
- "@tanstack/react-router": "1.19.1"
17
+ "@tanstack/react-router": "1.19.1",
18
+ "@trackunit/shared-utils": "*"
18
19
  },
19
20
  "module": "./index.esm.js",
20
21
  "main": "./index.cjs.js"
package/src/debugger.d.ts CHANGED
@@ -1,5 +1,11 @@
1
1
  import React from "react";
2
2
  type PropsToWatch<P> = P extends object ? P : never;
3
+ /**
4
+ * Differentiate between the first and subsequent renders.
5
+ *
6
+ * @returns {boolean} Returns true if it is the first render, false otherwise.
7
+ */
8
+ export declare const useIsFirstRender: () => boolean;
3
9
  /**
4
10
  * Logs props that have changed.
5
11
  * Use this for debugging which props force a component to re-render.