@trackunit/react-core-contexts-test 0.1.47 → 0.1.49
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/HookRenderer.cjs +1 -0
- package/HookRenderer.js +1 -0
- package/index.cjs +2 -0
- package/index.js +2 -1
- package/index2.cjs +45 -0
- package/index2.js +45 -1
- package/package.json +3 -3
- package/src/index.d.ts +1 -0
- package/src/useLogPropsChanged.d.ts +11 -0
package/HookRenderer.cjs
CHANGED
package/HookRenderer.js
CHANGED
package/index.cjs
CHANGED
|
@@ -12,6 +12,7 @@ require('react-router-dom');
|
|
|
12
12
|
require('@apollo/client');
|
|
13
13
|
require('@apollo/client/link/error');
|
|
14
14
|
require('@apollo/client/testing');
|
|
15
|
+
require('react');
|
|
15
16
|
require('graphql');
|
|
16
17
|
|
|
17
18
|
|
|
@@ -24,4 +25,5 @@ exports.mockCurrentUserContext = index.mockCurrentUserContext;
|
|
|
24
25
|
exports.mockEnvironmentContext = index.mockEnvironmentContext;
|
|
25
26
|
exports.queryFor = index.queryFor;
|
|
26
27
|
exports.rootContext = index.rootContext;
|
|
28
|
+
exports.useLogPropsChanged = index.useLogPropsChanged;
|
|
27
29
|
exports.validateIrisApp = index.validateIrisApp;
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { M as MockContextProviderBuilder, d as doNothing, f as flushPromises, b as flushPromisesInAct, m as mockCurrentUserContext, a as mockEnvironmentContext, q as queryFor, r as rootContext, v as validateIrisApp } from './index2.js';
|
|
1
|
+
export { M as MockContextProviderBuilder, d as doNothing, f as flushPromises, b as flushPromisesInAct, m as mockCurrentUserContext, a as mockEnvironmentContext, q as queryFor, r as rootContext, u as useLogPropsChanged, v as validateIrisApp } from './index2.js';
|
|
2
2
|
import 'react/jsx-runtime';
|
|
3
3
|
import '@testing-library/react';
|
|
4
4
|
import '@trackunit/react-core-contexts-api';
|
|
@@ -8,4 +8,5 @@ import 'react-router-dom';
|
|
|
8
8
|
import '@apollo/client';
|
|
9
9
|
import '@apollo/client/link/error';
|
|
10
10
|
import '@apollo/client/testing';
|
|
11
|
+
import 'react';
|
|
11
12
|
import 'graphql';
|
package/index2.cjs
CHANGED
|
@@ -9,6 +9,7 @@ var reactRouterDom = require('react-router-dom');
|
|
|
9
9
|
var client = require('@apollo/client');
|
|
10
10
|
var error = require('@apollo/client/link/error');
|
|
11
11
|
var testing = require('@apollo/client/testing');
|
|
12
|
+
var react$1 = require('react');
|
|
12
13
|
var graphql = require('graphql');
|
|
13
14
|
|
|
14
15
|
/******************************************************************************
|
|
@@ -380,6 +381,49 @@ const TestRoot = tailwindStyledComponents.tw.div `
|
|
|
380
381
|
inline-block;
|
|
381
382
|
`;
|
|
382
383
|
|
|
384
|
+
/**
|
|
385
|
+
* Logs props that have changed.
|
|
386
|
+
* Use this for debugging which props force a component to re-render.
|
|
387
|
+
* This is a hook version of the class component lifecycle method `componentDidUpdate`.
|
|
388
|
+
* ALWAYS wrap in your own object.
|
|
389
|
+
*
|
|
390
|
+
* @param propsToWatch all the props to watch for changes
|
|
391
|
+
*/
|
|
392
|
+
const useLogPropsChanged = (propsToWatch) => {
|
|
393
|
+
var _a;
|
|
394
|
+
const prevPropsRef = react$1.useRef(propsToWatch);
|
|
395
|
+
const parentCaller = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n")[2].trim();
|
|
396
|
+
react$1.useEffect(() => {
|
|
397
|
+
const changedProps = Object.entries(propsToWatch !== null && propsToWatch !== void 0 ? propsToWatch : {}).reduce((result, [key, value]) => {
|
|
398
|
+
if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
|
|
399
|
+
result[key] = [prevPropsRef.current[key], value];
|
|
400
|
+
}
|
|
401
|
+
return result;
|
|
402
|
+
}, [Object.keys(propsToWatch !== null && propsToWatch !== void 0 ? propsToWatch : {})]);
|
|
403
|
+
if (Object.keys(changedProps).length > 0) {
|
|
404
|
+
// eslint-disable-next-line no-console
|
|
405
|
+
Object.keys(changedProps).forEach(changedProp => {
|
|
406
|
+
console.log("Props changed:", changedProp, parentCaller);
|
|
407
|
+
// JSON stringify is used to avoid console.table from logging the object reference
|
|
408
|
+
const result = JSON.parse(JSON.stringify(changedProps[changedProp]));
|
|
409
|
+
const result0 = result[0];
|
|
410
|
+
const result1 = result[1];
|
|
411
|
+
result0 &&
|
|
412
|
+
Object.keys(result0).forEach(prop => {
|
|
413
|
+
result0[prop] = JSON.stringify(result0[prop]);
|
|
414
|
+
});
|
|
415
|
+
result1 &&
|
|
416
|
+
Object.keys(result1).forEach(prop => {
|
|
417
|
+
result1[prop] = JSON.stringify(result1[prop]);
|
|
418
|
+
});
|
|
419
|
+
console.table([result0, result1]);
|
|
420
|
+
});
|
|
421
|
+
console.dir(changedProps);
|
|
422
|
+
}
|
|
423
|
+
prevPropsRef.current = propsToWatch;
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
|
|
383
427
|
/**
|
|
384
428
|
*
|
|
385
429
|
* @param document Document that represents the specific GQL query / mutation schema.
|
|
@@ -468,4 +512,5 @@ exports.mockCurrentUserContext = mockCurrentUserContext;
|
|
|
468
512
|
exports.mockEnvironmentContext = mockEnvironmentContext;
|
|
469
513
|
exports.queryFor = queryFor;
|
|
470
514
|
exports.rootContext = rootContext;
|
|
515
|
+
exports.useLogPropsChanged = useLogPropsChanged;
|
|
471
516
|
exports.validateIrisApp = validateIrisApp;
|
package/index2.js
CHANGED
|
@@ -7,6 +7,7 @@ import { MemoryRouter } from 'react-router-dom';
|
|
|
7
7
|
import { ApolloLink } from '@apollo/client';
|
|
8
8
|
import { onError } from '@apollo/client/link/error';
|
|
9
9
|
import { MockLink, MockedProvider } from '@apollo/client/testing';
|
|
10
|
+
import { useRef, useEffect } from 'react';
|
|
10
11
|
import { GraphQLError } from 'graphql';
|
|
11
12
|
|
|
12
13
|
/******************************************************************************
|
|
@@ -378,6 +379,49 @@ const TestRoot = tw.div `
|
|
|
378
379
|
inline-block;
|
|
379
380
|
`;
|
|
380
381
|
|
|
382
|
+
/**
|
|
383
|
+
* Logs props that have changed.
|
|
384
|
+
* Use this for debugging which props force a component to re-render.
|
|
385
|
+
* This is a hook version of the class component lifecycle method `componentDidUpdate`.
|
|
386
|
+
* ALWAYS wrap in your own object.
|
|
387
|
+
*
|
|
388
|
+
* @param propsToWatch all the props to watch for changes
|
|
389
|
+
*/
|
|
390
|
+
const useLogPropsChanged = (propsToWatch) => {
|
|
391
|
+
var _a;
|
|
392
|
+
const prevPropsRef = useRef(propsToWatch);
|
|
393
|
+
const parentCaller = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n")[2].trim();
|
|
394
|
+
useEffect(() => {
|
|
395
|
+
const changedProps = Object.entries(propsToWatch !== null && propsToWatch !== void 0 ? propsToWatch : {}).reduce((result, [key, value]) => {
|
|
396
|
+
if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
|
|
397
|
+
result[key] = [prevPropsRef.current[key], value];
|
|
398
|
+
}
|
|
399
|
+
return result;
|
|
400
|
+
}, [Object.keys(propsToWatch !== null && propsToWatch !== void 0 ? propsToWatch : {})]);
|
|
401
|
+
if (Object.keys(changedProps).length > 0) {
|
|
402
|
+
// eslint-disable-next-line no-console
|
|
403
|
+
Object.keys(changedProps).forEach(changedProp => {
|
|
404
|
+
console.log("Props changed:", changedProp, parentCaller);
|
|
405
|
+
// JSON stringify is used to avoid console.table from logging the object reference
|
|
406
|
+
const result = JSON.parse(JSON.stringify(changedProps[changedProp]));
|
|
407
|
+
const result0 = result[0];
|
|
408
|
+
const result1 = result[1];
|
|
409
|
+
result0 &&
|
|
410
|
+
Object.keys(result0).forEach(prop => {
|
|
411
|
+
result0[prop] = JSON.stringify(result0[prop]);
|
|
412
|
+
});
|
|
413
|
+
result1 &&
|
|
414
|
+
Object.keys(result1).forEach(prop => {
|
|
415
|
+
result1[prop] = JSON.stringify(result1[prop]);
|
|
416
|
+
});
|
|
417
|
+
console.table([result0, result1]);
|
|
418
|
+
});
|
|
419
|
+
console.dir(changedProps);
|
|
420
|
+
}
|
|
421
|
+
prevPropsRef.current = propsToWatch;
|
|
422
|
+
});
|
|
423
|
+
};
|
|
424
|
+
|
|
381
425
|
/**
|
|
382
426
|
*
|
|
383
427
|
* @param document Document that represents the specific GQL query / mutation schema.
|
|
@@ -457,4 +501,4 @@ const validateIrisApp = (irisApp) => __awaiter(void 0, void 0, void 0, function*
|
|
|
457
501
|
return null;
|
|
458
502
|
});
|
|
459
503
|
|
|
460
|
-
export { MockContextProviderBuilder as M, __awaiter as _, mockEnvironmentContext as a, flushPromisesInAct as b, doNothing as d, flushPromises as f, mockCurrentUserContext as m, queryFor as q, rootContext as r, validateIrisApp as v };
|
|
504
|
+
export { MockContextProviderBuilder as M, __awaiter as _, mockEnvironmentContext as a, flushPromisesInAct as b, doNothing as d, flushPromises as f, mockCurrentUserContext as m, queryFor as q, rootContext as r, useLogPropsChanged 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.
|
|
3
|
+
"version": "0.1.49",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@apollo/client": "3.7.10",
|
|
12
12
|
"@trackunit/react-core-contexts-api": "0.2.25",
|
|
13
|
-
"@trackunit/react-core-hooks": "0.2.
|
|
14
|
-
"@trackunit/tailwind-styled-components": "0.0.
|
|
13
|
+
"@trackunit/react-core-hooks": "0.2.44",
|
|
14
|
+
"@trackunit/tailwind-styled-components": "0.0.56",
|
|
15
15
|
"graphql": "15.8.0",
|
|
16
16
|
"react": "18.2.0",
|
|
17
17
|
"react-router-dom": "6.4.5"
|
package/src/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./MockContextProviderBuilder";
|
|
2
2
|
export * from "./mocks/mockCurrentUserContext";
|
|
3
3
|
export * from "./mocks/mockEnvironmentContext";
|
|
4
|
+
export * from "./useLogPropsChanged";
|
|
4
5
|
export * from "./utils/doNothing";
|
|
5
6
|
export * from "./utils/queryFor";
|
|
6
7
|
export * from "./utils/validateIrisApp";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type PropsToWatch<P> = P extends object ? P : never;
|
|
2
|
+
/**
|
|
3
|
+
* Logs props that have changed.
|
|
4
|
+
* Use this for debugging which props force a component to re-render.
|
|
5
|
+
* This is a hook version of the class component lifecycle method `componentDidUpdate`.
|
|
6
|
+
* ALWAYS wrap in your own object.
|
|
7
|
+
*
|
|
8
|
+
* @param propsToWatch all the props to watch for changes
|
|
9
|
+
*/
|
|
10
|
+
export declare const useLogPropsChanged: <P extends object>(propsToWatch: PropsToWatch<P> | null) => void;
|
|
11
|
+
export {};
|