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,13 +10,16 @@ import {
8
10
NavLink ,
9
11
Switch ,
10
12
} from 'react-router-dom' ;
13
+ import { Component } from 'react' ;
11
14
import RenderingFrequency from './RenderingFrequency' ;
12
15
// import Switch from '@material-ui/core/Switch';
13
16
import BarGraph from './BarGraph' ;
14
17
import BarGraphComparison from './BarGraphComparison' ;
15
18
import { useStoreContext } from '../store' ;
16
19
// import snapshots from './snapshots';
17
- import { Component } from 'react' ;
20
+ import snapshots from './snapshots' ;
21
+
22
+ 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' ] ;
18
23
19
24
/* NOTES
20
25
Issue - Not fully compatible with recoil apps. Reference the recoil-todo-test.
@@ -34,15 +39,17 @@ interface BarStackProps {
34
39
hierarchy : any ;
35
40
}
36
41
37
-
38
-
42
+ const formatRenderTime = time => {
43
+ time = time . toFixed ( 3 ) ;
44
+ return `${ time } ms ` ;
45
+ } ;
39
46
// function getComponentsArr(componentName, snapshots, node) {
40
47
// //Input: Name of component and all snapshots
41
48
// //Output: One array of each individual snapshot
42
49
43
50
// //NOTE:
44
51
// //Every snapshot is an object with a children array with a snapshot that also has a children array etc
45
- // //Children arrays more than one signify siblings
52
+ // //Children arrays more than one signify siblings
46
53
47
54
// }
48
55
// // snapshots.map(rootNode => {
@@ -57,37 +64,77 @@ interface BarStackProps {
57
64
// // }
58
65
// // }
59
66
// // })
67
+ const makePropsPretty = data => {
68
+ const propsFormat = [ ] ;
69
+ const nestedObj = [ ] ;
70
+ // console.log('show me the data we are getting', data);
71
+ if ( typeof data !== 'object' ) {
72
+ return data ;
73
+ }
74
+ for ( const key in data ) {
75
+ if ( data [ key ] !== 'reactFiber' && typeof data [ key ] !== 'object' && exclude . includes ( key ) !== true ) {
76
+ propsFormat . push ( < p className = "stateprops" >
77
+ { `${ key } : ${ data [ key ] } ` }
78
+ </ p > ) ;
79
+ } else if ( data [ key ] !== 'reactFiber' && typeof data [ key ] === 'object' && exclude . includes ( key ) !== true ) {
80
+ const result = makePropsPretty ( data [ key ] ) ;
81
+ nestedObj . push ( result ) ;
82
+ }
83
+ }
84
+ if ( nestedObj ) {
85
+ propsFormat . push ( nestedObj ) ;
86
+ }
87
+ // console.log('this is propsformat', propsFormat);
88
+ return propsFormat ;
89
+ } ;
60
90
61
91
const collectNodes = ( snaps , componentName ) => {
62
92
const componentsResult = [ ] ;
63
- // console.log("This is the snapshots", snaps);
64
- // componentsResult.splice(0, componentsResult.length); { /* We used the .splice method here to ensure that nodeList did not accumulate with page refreshes */ }
65
- // componentsResult.push(snaps);
66
-
93
+ let trackChanges = 0 ;
94
+ let newChange = true ;
67
95
for ( let x = 0 ; x < snaps . length ; x ++ ) {
68
- const snapshotList = [ ]
96
+ const snapshotList = [ ] ;
69
97
snapshotList . push ( snaps [ x ] ) ;
70
-
71
98
for ( let i = 0 ; i < snapshotList . length ; i ++ ) {
72
-
73
99
const cur = snapshotList [ i ] ;
74
100
if ( cur . name === componentName ) {
75
- componentsResult . push ( cur . componentData . props ) ;
101
+ // compare the last pushed component Data from the array to the current one to see if there are differences
102
+ if ( x !== 0 && componentsResult . length !== 0 ) {
103
+ // needs to be stringified because values are hard to determine if true or false if in they're seen as objects
104
+ if ( JSON . stringify ( Object . values ( componentsResult [ newChange ? componentsResult . length - 1 : trackChanges ] ) [ 0 ] ) !== JSON . stringify ( cur . componentData . props ) ) {
105
+ newChange = true ;
106
+ const props = { [ `snapshot${ x } ` ] : { ...cur . componentData . props , rendertime : formatRenderTime ( cur . componentData . actualDuration ) } } ;
107
+ //props[`snapshot${x}`].rendertime = formatRenderTime(cur.componentData.actualDuration);
108
+ componentsResult . push ( props ) ;
109
+ } else {
110
+ newChange = false ;
111
+ trackChanges = componentsResult . length - 1 ;
112
+ const props = { [ `snapshot${ x } ` ] : 'Same state as prior snapshot' , rendertime : formatRenderTime ( cur . componentData . actualDuration ) } ;
113
+ componentsResult . push ( props ) ;
114
+ }
115
+ } else {
116
+ const props = { [ `snapshot${ x } ` ] : { ...cur . componentData . props } } ;
117
+ props [ `snapshot${ x } ` ] . rendertime = formatRenderTime ( cur . componentData . actualDuration ) ;
118
+ componentsResult . push ( props ) ;
119
+ }
76
120
break ;
77
121
}
78
122
if ( cur . children && cur . children . length > 0 ) {
79
- for ( let child of cur . children ) {
123
+ for ( const child of cur . children ) {
80
124
snapshotList . push ( child ) ;
81
125
}
82
126
}
83
127
}
84
- }
85
- //console.log('componentsResult looks like: ', componentsResult);
128
+ }
129
+ // console.log('componentsResult looks like: ', componentsResult);
130
+ for ( let i = 0 ; i < componentsResult . length ; i ++ ) {
131
+ for ( const componentSnapshot in componentsResult [ i ] ) {
132
+ componentsResult [ i ] [ componentSnapshot ] = makePropsPretty ( componentsResult [ i ] [ componentSnapshot ] ) ;
133
+ }
134
+ }
135
+ console . log ( 'we should be seeing react components with information' , componentsResult ) ;
86
136
return componentsResult ;
87
- }
88
-
89
-
90
-
137
+ } ;
91
138
92
139
/* DATA HANDLING HELPER FUNCTIONS */
93
140
const traverse = ( snapshot , data , snapshots , currTotalRender = 0 ) => {
@@ -113,7 +160,7 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
113
160
renderFrequency : 0 ,
114
161
totalRenderTime : 0 ,
115
162
rtid : '' ,
116
- props : { } ,
163
+ information : { } ,
117
164
} ;
118
165
if ( child . state !== 'stateless' ) data . componentData [ componentName ] . stateType = 'stateful' ;
119
166
}
@@ -131,7 +178,8 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
131
178
data . componentData [ componentName ] . totalRenderTime += renderTime ;
132
179
// Get rtid for the hovering feature
133
180
data . componentData [ componentName ] . rtid = child . rtid ;
134
- data . componentData [ componentName ] . props = collectNodes ( snapshots , child . name ) ;
181
+ data . componentData [ componentName ] . information = collectNodes ( snapshots , child . name ) . flat ( Infinity ) ;
182
+ // console.log('what is the result', data.componentData[componentName].information);
135
183
traverse ( snapshot . children [ idx ] , data , snapshots , currTotalRender ) ;
136
184
} ) ;
137
185
// reassigns total render time to max render time
@@ -144,13 +192,13 @@ const allStorage = () => {
144
192
const values = [ ] ;
145
193
const keys = Object . keys ( localStorage ) ;
146
194
let i = keys . length ;
147
- console . log ( 'allstorage keys' , keys ) ;
195
+ // console.log('allstorage keys', keys);
148
196
149
197
while ( i -- ) {
150
198
const series = localStorage . getItem ( keys [ i ] ) ;
151
199
values . push ( JSON . parse ( series ) ) ;
152
200
}
153
- console . log ( 'allstorage values' , values ) ;
201
+ // console.log('allstorage values', values);
154
202
return values ;
155
203
} ;
156
204
@@ -172,7 +220,7 @@ const getPerfMetrics = (snapshots, snapshotsIds): {} => {
172
220
componentData : { } ,
173
221
maxTotalRender : 0 ,
174
222
} ;
175
- console . log ( 'show me all of the snapshots' , snapshots ) ;
223
+ // console.log('show me all of the snapshots', snapshots);
176
224
snapshots . forEach ( ( snapshot , i ) => {
177
225
perfData . barStack . push ( { snapshotId : snapshotsIds [ i ] } ) ;
178
226
traverse ( snapshot , perfData , snapshots ) ;
@@ -192,6 +240,7 @@ const PerformanceVisx = (props: BarStackProps) => {
192
240
const [ comparisonData , setComparisonData ] = useState ( ) ;
193
241
const NO_STATE_MSG = 'No state change detected. Trigger an event to change state' ;
194
242
const data = getPerfMetrics ( snapshots , getSnapshotIds ( hierarchy ) ) ;
243
+ // console.log('this is line 220', data);
195
244
196
245
const renderComparisonBargraph = ( ) => {
197
246
if ( hierarchy ) {
@@ -213,10 +262,9 @@ const PerformanceVisx = (props: BarStackProps) => {
213
262
} ;
214
263
215
264
const renderComponentDetailsView = ( ) => {
216
- console . log ( 'show me snapshots' , snapshots )
217
- console . log ( 'what is heirarchy' , hierarchy ) ;
218
- console . log ( 'this is the info for rendering frequency' , data . componentData ) ;
265
+ // console.log('this is the info for rendering frequency', data.componentData);
219
266
if ( hierarchy ) {
267
+ // console.log('this is line 246', data.comparisonData);
220
268
return < RenderingFrequency data = { data . componentData } /> ;
221
269
}
222
270
return < div className = "noState" > { NO_STATE_MSG } </ div > ;
0 commit comments