Skip to content

Commit 3c251a1

Browse files
andytsou19vnguyen95
andcommitted
working on changing render position pushing current changes
Co-authored-by: Viet Nguyen <[email protected]>
1 parent 32f94cf commit 3c251a1

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

src/app/components/PerformanceVisx.tsx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import {
1111
Switch,
1212
} from 'react-router-dom';
1313
import { Component } from 'react';
14+
import { render } from 'react-dom';
1415
import RenderingFrequency from './RenderingFrequency';
1516
// import Switch from '@material-ui/core/Switch';
1617
import BarGraph from './BarGraph';
1718
import BarGraphComparison from './BarGraphComparison';
1819
import { useStoreContext } from '../store';
1920
// import snapshots from './snapshots';
2021
import snapshots from './snapshots';
21-
import { render } from 'react-dom';
2222

2323
const exclude = ['childExpirationTime', 'staticContext', '_debugSource', 'actualDuration', 'actualStartTime', 'treeBaseDuration', '_debugID', '_debugIsCurrentlyTiming', 'selfBaseDuration', 'expirationTime', 'effectTag', 'alternate', '_owner', '_store', 'get key', 'ref', '_self', '_source', 'firstBaseUpdate', 'updateQueue', 'lastBaseUpdate', 'shared', 'responders', 'pending', 'lanes', 'childLanes', 'effects', 'memoizedState', 'pendingProps', 'lastEffect', 'firstEffect', 'tag', 'baseState', 'baseQueue', 'dependencies', 'Consumer', 'context', '_currentRenderer', '_currentRenderer2', 'mode', 'flags', 'nextEffect', 'sibling', 'create', 'deps', 'next', 'destroy', 'parentSub', 'child', 'key', 'return', 'children', '$$typeof', '_threadCount', '_calculateChangedBits', '_currentValue', '_currentValue2', 'Provider', '_context', 'stateNode', 'elementType', 'type'];
2424

@@ -72,7 +72,7 @@ const makePropsPretty = data => {
7272
if (data[key] !== 'reactFiber' && typeof data[key] !== 'object' && exclude.includes(key) !== true) {
7373
propsFormat.push(<p className="stateprops">
7474
{`${key}: ${data[key]}`}
75-
</p>);
75+
</p>);
7676
} else if (data[key] !== 'reactFiber' && typeof data[key] === 'object' && exclude.includes(key) !== true) {
7777
const result = makePropsPretty(data[key]);
7878
nestedObj.push(result);
@@ -87,6 +87,7 @@ const makePropsPretty = data => {
8787

8888
const collectNodes = (snaps, componentName) => {
8989
const componentsResult = [];
90+
const renderResult = [];
9091
let trackChanges = 0;
9192
let newChange = true;
9293
for (let x = 0; x < snaps.length; x++) {
@@ -100,6 +101,8 @@ const collectNodes = (snaps, componentName) => {
100101
);
101102
if (renderTime === 0) {
102103
break;
104+
} else {
105+
renderResult.push(renderTime);
103106
}
104107
console.log('show me the render time', renderTime);
105108
// compare the last pushed component Data from the array to the current one to see if there are differences
@@ -109,11 +112,12 @@ const collectNodes = (snaps, componentName) => {
109112
newChange = true;
110113
// const props = { [`snapshot${x}`]: { rendertime: formatRenderTime(cur.componentData.actualDuration), ...cur.componentData.props } };
111114
const props = { [`snapshot${x}`]: { ...cur.componentData.props } };
115+
console.log('show me props structure', props)
112116
componentsResult.push(props);
113117
} else {
114118
newChange = false;
115119
trackChanges = componentsResult.length - 1;
116-
const props = { [`snapshot${x}`]: 'Same state as prior snapshot' };
120+
const props = { [`snapshot${x}`]: { state: 'Same state as prior snapshot' } };
117121
componentsResult.push(props);
118122
}
119123
} else {
@@ -132,13 +136,23 @@ const collectNodes = (snaps, componentName) => {
132136
}
133137
}
134138
// console.log('componentsResult looks like: ', componentsResult);
135-
for (let i = 0; i < componentsResult.length; i++) {
136-
for (const componentSnapshot in componentsResult[i]) {
137-
componentsResult[i][componentSnapshot] = makePropsPretty(componentsResult[i][componentSnapshot]);
139+
140+
// console.log('we should be seeing react components with information', componentsResult);
141+
// componentsResult.push(renderResult);
142+
const finalResults = componentsResult.map((e, index) => {
143+
const name = Object.keys(e)[0];
144+
console.log('this is name', name, 'show me e', e);
145+
e[name].rendertime = renderResult[index];
146+
console.log('this is e', e);
147+
return e;
148+
});
149+
for (let i = 0; i < finalResults.length; i++) {
150+
for (const componentSnapshot in finalResults[i]) {
151+
finalResults[i][componentSnapshot] = makePropsPretty(finalResults[i][componentSnapshot]);
138152
}
139153
}
140-
// console.log('we should be seeing react components with information', componentsResult);
141-
return componentsResult;
154+
console.log('finalresults', finalResults);
155+
return finalResults;
142156
};
143157

144158
/* DATA HANDLING HELPER FUNCTIONS */
@@ -183,14 +197,7 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
183197
data.componentData[componentName].totalRenderTime += renderTime;
184198
// Get rtid for the hovering feature
185199
data.componentData[componentName].rtid = child.rtid;
186-
data.componentData[componentName].information = collectNodes(snapshots, child.name).flat(Infinity);
187-
if(renderTime !== 0) {
188-
// eslint-disable-next-line react/jsx-one-expression-per-line
189-
data.componentData[componentName].information.rendertime = <p>Render Time:{' '}{renderTime}{' '}</p>;
190-
}
191-
// (
192-
// );
193-
// console.log('what is the result', data.componentData[componentName].information);
200+
data.componentData[componentName].information = collectNodes(snapshots, child.name);
194201
traverse(snapshot.children[idx], data, snapshots, currTotalRender);
195202
});
196203
// reassigns total render time to max render time

src/app/components/RenderingFrequency.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* eslint-disable jsx-a11y/no-static-element-interactions */
33
/* eslint-disable react/prop-types */
44
import React, { useState } from 'react';
5+
import { render } from 'react-dom';
56
import { onHover, onHoverExit } from '../actions/actions';
67
import { useStoreContext } from '../store';
78

@@ -50,9 +51,10 @@ const ComponentCard = props => {
5051
// dispatch(onHoverExit(rtid));
5152
// };
5253

53-
5454
// render time for each component from each snapshot
5555
// differences in state change that happened prior;
56+
57+
5658
const dataComponentArray = [];
5759
for (let i = 0; i < information.length; i++) {
5860
dataComponentArray.push(<DataComponent header={Object.keys(information[i])} paragraphs={Object.values(information[i])} />);
@@ -103,6 +105,7 @@ const DataComponent = props => {
103105
header,
104106
paragraphs,
105107
} = props;
108+
106109
// const [{ tabs, currentTab }, dispatch] = useStoreContext();
107110
return (
108111
<div>

0 commit comments

Comments
 (0)