1
+ /* eslint-disable guard-for-in */
2
+ /* eslint-disable no-restricted-syntax */
1
3
// @ts -nocheck
2
4
import React , { useState } from 'react' ;
3
5
import FormControlLabel from '@material-ui/core/FormControlLabel' ;
@@ -8,11 +10,17 @@ import {
8
10
NavLink ,
9
11
Switch ,
10
12
} from 'react-router-dom' ;
13
+ import { Component } from 'react' ;
14
+ import { render } from 'react-dom' ;
11
15
import RenderingFrequency from './RenderingFrequency' ;
12
16
// import Switch from '@material-ui/core/Switch';
13
17
import BarGraph from './BarGraph' ;
14
18
import BarGraphComparison from './BarGraphComparison' ;
15
19
import { useStoreContext } from '../store' ;
20
+ // import snapshots from './snapshots';
21
+ import snapshots from './snapshots' ;
22
+
23
+ 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' ] ;
16
24
17
25
/* NOTES
18
26
Issue - Not fully compatible with recoil apps. Reference the recoil-todo-test.
@@ -32,8 +40,123 @@ interface BarStackProps {
32
40
hierarchy : any ;
33
41
}
34
42
43
+ // function getComponentsArr(componentName, snapshots, node) {
44
+ // //Input: Name of component and all snapshots
45
+ // //Output: One array of each individual snapshot
46
+
47
+ // //NOTE:
48
+ // //Every snapshot is an object with a children array with a snapshot that also has a children array etc
49
+ // //Children arrays more than one signify siblings
50
+
51
+ // }
52
+ // // snapshots.map(rootNode => {
53
+ // // // rootNode.name
54
+ // // let currNode = rootNode
55
+ // // while (currNode) {
56
+ // // if (currNode.name === componentName) {
57
+ // // return currNode.componentData.props
58
+ // // } else {
59
+ // // currNode = currNode.children[0]
60
+ // // currNode = currNode.children[1]
61
+ // // }
62
+ // // }
63
+ // // })
64
+ const makePropsPretty = data => {
65
+ const propsFormat = [ ] ;
66
+ const nestedObj = [ ] ;
67
+ // console.log('show me the data we are getting', data);
68
+ if ( typeof data !== 'object' ) {
69
+ return < p > { data } </ p > ;
70
+ }
71
+ for ( const key in data ) {
72
+ if ( data [ key ] !== 'reactFiber' && typeof data [ key ] !== 'object' && exclude . includes ( key ) !== true ) {
73
+ propsFormat . push ( < p className = "stateprops" >
74
+ { `${ key } : ${ data [ key ] } ` }
75
+ </ p > ) ;
76
+ } else if ( data [ key ] !== 'reactFiber' && typeof data [ key ] === 'object' && exclude . includes ( key ) !== true ) {
77
+ const result = makePropsPretty ( data [ key ] ) ;
78
+ nestedObj . push ( result ) ;
79
+ }
80
+ }
81
+ if ( nestedObj ) {
82
+ propsFormat . push ( nestedObj ) ;
83
+ }
84
+ // console.log('this is propsformat', propsFormat);
85
+ return propsFormat ;
86
+ } ;
87
+
88
+ const collectNodes = ( snaps , componentName ) => {
89
+ const componentsResult = [ ] ;
90
+ const renderResult = [ ] ;
91
+ let trackChanges = 0 ;
92
+ let newChange = true ;
93
+ for ( let x = 0 ; x < snaps . length ; x ++ ) {
94
+ const snapshotList = [ ] ;
95
+ snapshotList . push ( snaps [ x ] ) ;
96
+ for ( let i = 0 ; i < snapshotList . length ; i ++ ) {
97
+ const cur = snapshotList [ i ] ;
98
+ if ( cur . name === componentName ) {
99
+ const renderTime = Number (
100
+ Number . parseFloat ( cur . componentData . actualDuration ) . toPrecision ( 5 ) ,
101
+ ) ;
102
+ if ( renderTime === 0 ) {
103
+ break ;
104
+ } else {
105
+ renderResult . push ( renderTime ) ;
106
+ }
107
+ console . log ( 'show me the render time' , renderTime ) ;
108
+ // compare the last pushed component Data from the array to the current one to see if there are differences
109
+ if ( x !== 0 && componentsResult . length !== 0 ) {
110
+ // needs to be stringified because values are hard to determine if true or false if in they're seen as objects
111
+ if ( JSON . stringify ( Object . values ( componentsResult [ newChange ? componentsResult . length - 1 : trackChanges ] ) [ 0 ] ) !== JSON . stringify ( cur . componentData . props ) ) {
112
+ newChange = true ;
113
+ // const props = { [`snapshot${x}`]: { rendertime: formatRenderTime(cur.componentData.actualDuration), ...cur.componentData.props } };
114
+ const props = { [ `snapshot${ x } ` ] : { ...cur . componentData . props } } ;
115
+ console . log ( 'show me props structure' , props )
116
+ componentsResult . push ( props ) ;
117
+ } else {
118
+ newChange = false ;
119
+ trackChanges = componentsResult . length - 1 ;
120
+ const props = { [ `snapshot${ x } ` ] : { state : 'Same state as prior snapshot' } } ;
121
+ componentsResult . push ( props ) ;
122
+ }
123
+ } else {
124
+ // const props = { [`snapshot${x}`]: { ...cur.componentData.props}};
125
+ // props[`snapshot${x}`].rendertime = formatRenderTime(cur.componentData.actualDuration);
126
+ const props = { [ `snapshot${ x } ` ] : { ...cur . componentData . props } } ;
127
+ componentsResult . push ( props ) ;
128
+ }
129
+ break ;
130
+ }
131
+ if ( cur . children && cur . children . length > 0 ) {
132
+ for ( const child of cur . children ) {
133
+ snapshotList . push ( child ) ;
134
+ }
135
+ }
136
+ }
137
+ }
138
+ // console.log('componentsResult looks like: ', componentsResult);
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 ] ) ;
152
+ }
153
+ }
154
+ console . log ( 'finalresults' , finalResults ) ;
155
+ return finalResults ;
156
+ } ;
157
+
35
158
/* DATA HANDLING HELPER FUNCTIONS */
36
- const traverse = ( snapshot , data , currTotalRender = 0 ) => {
159
+ const traverse = ( snapshot , data , snapshots , currTotalRender = 0 ) => {
37
160
if ( ! snapshot . children [ 0 ] ) return ;
38
161
39
162
// loop through snapshots
@@ -56,24 +179,26 @@ const traverse = (snapshot, data, currTotalRender = 0) => {
56
179
renderFrequency : 0 ,
57
180
totalRenderTime : 0 ,
58
181
rtid : '' ,
182
+ information : { } ,
59
183
} ;
60
184
if ( child . state !== 'stateless' ) data . componentData [ componentName ] . stateType = 'stateful' ;
61
185
}
62
186
// increment render frequencies
63
187
if ( renderTime > 0 ) {
64
- console . log ( 'what is the child' , child ) ;
65
- console . log ( 'por que?' , data . componentData [ componentName ] ) ;
188
+ // console.log('what is the child', child);
189
+ // console.log('por que?', data.componentData[componentName]);
66
190
data . componentData [ componentName ] . renderFrequency ++ ;
67
191
} else {
68
- console . log ( 'what is the child' , child ) ;
69
- console . log ( 'we dont increment here' , data . componentData [ componentName ] , 'and the child' , child ) ;
192
+ // console.log('what is the child', child);
193
+ // console.log('we dont increment here', data.componentData[componentName], 'and the child', child);
70
194
}
71
195
72
196
// add to total render time
73
197
data . componentData [ componentName ] . totalRenderTime += renderTime ;
74
198
// Get rtid for the hovering feature
75
199
data . componentData [ componentName ] . rtid = child . rtid ;
76
- traverse ( snapshot . children [ idx ] , data , currTotalRender ) ;
200
+ data . componentData [ componentName ] . information = collectNodes ( snapshots , child . name ) ;
201
+ traverse ( snapshot . children [ idx ] , data , snapshots , currTotalRender ) ;
77
202
} ) ;
78
203
// reassigns total render time to max render time
79
204
data . maxTotalRender = Math . max ( currTotalRender , data . maxTotalRender ) ;
@@ -85,13 +210,13 @@ const allStorage = () => {
85
210
const values = [ ] ;
86
211
const keys = Object . keys ( localStorage ) ;
87
212
let i = keys . length ;
88
- console . log ( 'allstorage keys' , keys ) ;
213
+ // console.log('allstorage keys', keys);
89
214
90
215
while ( i -- ) {
91
216
const series = localStorage . getItem ( keys [ i ] ) ;
92
217
values . push ( JSON . parse ( series ) ) ;
93
218
}
94
- console . log ( 'allstorage values' , values ) ;
219
+ // console.log('allstorage values', values);
95
220
return values ;
96
221
} ;
97
222
@@ -113,10 +238,10 @@ const getPerfMetrics = (snapshots, snapshotsIds): {} => {
113
238
componentData : { } ,
114
239
maxTotalRender : 0 ,
115
240
} ;
116
- console . log ( 'show me all of the snapshots' , snapshots ) ;
241
+ // console.log('show me all of the snapshots', snapshots);
117
242
snapshots . forEach ( ( snapshot , i ) => {
118
243
perfData . barStack . push ( { snapshotId : snapshotsIds [ i ] } ) ;
119
- traverse ( snapshot , perfData ) ;
244
+ traverse ( snapshot , perfData , snapshots ) ;
120
245
} ) ;
121
246
return perfData ;
122
247
} ;
@@ -133,6 +258,7 @@ const PerformanceVisx = (props: BarStackProps) => {
133
258
const [ comparisonData , setComparisonData ] = useState ( ) ;
134
259
const NO_STATE_MSG = 'No state change detected. Trigger an event to change state' ;
135
260
const data = getPerfMetrics ( snapshots , getSnapshotIds ( hierarchy ) ) ;
261
+ // console.log('this is line 220', data);
136
262
137
263
const renderComparisonBargraph = ( ) => {
138
264
if ( hierarchy ) {
@@ -154,7 +280,9 @@ const PerformanceVisx = (props: BarStackProps) => {
154
280
} ;
155
281
156
282
const renderComponentDetailsView = ( ) => {
283
+ // console.log('this is the info for rendering frequency', data.componentData);
157
284
if ( hierarchy ) {
285
+ // console.log('this is line 246', data.comparisonData);
158
286
return < RenderingFrequency data = { data . componentData } /> ;
159
287
}
160
288
return < div className = "noState" > { NO_STATE_MSG } </ div > ;
0 commit comments