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' ;
@@ -16,7 +18,10 @@ import BarGraph from './BarGraph';
16
18
import BarGraphComparison from './BarGraphComparison' ;
17
19
import { useStoreContext } from '../store' ;
18
20
// import snapshots from './snapshots';
19
- import { Component } from 'react' ;
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' ] ;
24
+
20
25
/* NOTES
21
26
Issue - Not fully compatible with recoil apps. Reference the recoil-todo-test.
22
27
Barstacks display inconsistently...however, almost always displays upon initial test app load or
@@ -26,56 +31,99 @@ to note - all snapshots do render (check HTML doc) within the chrome extension b
26
31
not display because height is not consistently passed to each bar. This side effect is only
27
32
seen in recoil apps...
28
33
*/
34
+
29
35
// typescript for PROPS from StateRoute.tsx
30
36
interface BarStackProps {
31
37
width : number ;
32
38
height : number ;
33
39
snapshots : [ ] ;
34
40
hierarchy : any ;
35
41
}
36
- // function getComponentsArr(componentName, snapshots, node) {
37
- // //Input: Name of component and all snapshots
38
- // //Output: One array of each individual snapshot
39
- // //NOTE:
40
- // //Every snapshot is an object with a children array with a snapshot that also has a children array etc
41
- // //Children arrays more than one signify siblings
42
- // }
43
- // // snapshots.map(rootNode => {
44
- // // // rootNode.name
45
- // // let currNode = rootNode
46
- // // while (currNode) {
47
- // // if (currNode.name === componentName) {
48
- // // return currNode.componentData.props
49
- // // } else {
50
- // // currNode = currNode.children[0]
51
- // // currNode = currNode.children[1]
52
- // // }
53
- // // }
54
- // // })
42
+
43
+ const makePropsPretty = data => {
44
+ const propsFormat = [ ] ;
45
+ const nestedObj = [ ] ;
46
+ if ( typeof data !== 'object' ) {
47
+ return < p > { data } </ p > ;
48
+ }
49
+ for ( const key in data ) {
50
+ if ( data [ key ] !== 'reactFiber' && typeof data [ key ] !== 'object' && exclude . includes ( key ) !== true ) {
51
+ propsFormat . push ( < p className = "stateprops" >
52
+ { `${ key } : ${ data [ key ] } ` }
53
+ </ p > ) ;
54
+ } else if ( data [ key ] !== 'reactFiber' && typeof data [ key ] === 'object' && exclude . includes ( key ) !== true ) {
55
+ const result = makePropsPretty ( data [ key ] ) ;
56
+ nestedObj . push ( result ) ;
57
+ }
58
+ }
59
+ if ( nestedObj ) {
60
+ propsFormat . push ( nestedObj ) ;
61
+ }
62
+ return propsFormat ;
63
+ } ;
64
+
55
65
const collectNodes = ( snaps , componentName ) => {
56
66
const componentsResult = [ ] ;
57
- // console.log("This is the snapshots", snaps) ;
58
- // componentsResult.splice(0, componentsResult.length); { /* We used the .splice method here to ensure that nodeList did not accumulate with page refreshes */ }
59
- // componentsResult.push(snaps) ;
67
+ const renderResult = [ ] ;
68
+ let trackChanges = 0 ;
69
+ let newChange = true ;
60
70
for ( let x = 0 ; x < snaps . length ; x ++ ) {
61
- const snapshotList = [ ]
71
+ const snapshotList = [ ] ;
62
72
snapshotList . push ( snaps [ x ] ) ;
63
73
for ( let i = 0 ; i < snapshotList . length ; i ++ ) {
64
74
const cur = snapshotList [ i ] ;
65
75
if ( cur . name === componentName ) {
66
- componentsResult . push ( cur . componentData . props ) ;
76
+ const renderTime = Number (
77
+ Number . parseFloat ( cur . componentData . actualDuration ) . toPrecision ( 5 ) ,
78
+ ) ;
79
+ if ( renderTime === 0 ) {
80
+ break ;
81
+ } else {
82
+ renderResult . push ( renderTime ) ;
83
+ }
84
+ // compare the last pushed component Data from the array to the current one to see if there are differences
85
+ if ( x !== 0 && componentsResult . length !== 0 ) {
86
+ // needs to be stringified because values are hard to determine if true or false if in they're seen as objects
87
+ if ( JSON . stringify ( Object . values ( componentsResult [ newChange ? componentsResult . length - 1 : trackChanges ] ) [ 0 ] ) !== JSON . stringify ( cur . componentData . props ) ) {
88
+ newChange = true ;
89
+ // const props = { [`snapshot${x}`]: { rendertime: formatRenderTime(cur.componentData.actualDuration), ...cur.componentData.props } };
90
+ const props = { [ `snapshot${ x } ` ] : { ...cur . componentData . props } } ;
91
+ componentsResult . push ( props ) ;
92
+ } else {
93
+ newChange = false ;
94
+ trackChanges = componentsResult . length - 1 ;
95
+ const props = { [ `snapshot${ x } ` ] : { state : 'Same state as prior snapshot' } } ;
96
+ componentsResult . push ( props ) ;
97
+ }
98
+ } else {
99
+ // const props = { [`snapshot${x}`]: { ...cur.componentData.props}};
100
+ // props[`snapshot${x}`].rendertime = formatRenderTime(cur.componentData.actualDuration);
101
+ const props = { [ `snapshot${ x } ` ] : { ...cur . componentData . props } } ;
102
+ componentsResult . push ( props ) ;
103
+ }
67
104
break ;
68
105
}
69
106
if ( cur . children && cur . children . length > 0 ) {
70
- for ( let child of cur . children ) {
107
+ for ( const child of cur . children ) {
71
108
snapshotList . push ( child ) ;
72
109
}
73
110
}
74
111
}
75
112
}
76
- //console.log('componentsResult looks like: ', componentsResult);
77
- return componentsResult ;
78
- }
113
+
114
+ const finalResults = componentsResult . map ( ( e , index ) => {
115
+ const name = Object . keys ( e ) [ 0 ] ;
116
+ e [ name ] . rendertime = renderResult [ index ] ;
117
+ return e ;
118
+ } ) ;
119
+ // for (let i = 0; i < finalResults.length; i++) {
120
+ // for (const componentSnapshot in finalResults[i]) {
121
+ // finalResults[i][componentSnapshot] = makePropsPretty(finalResults[i][componentSnapshot]).reverse();
122
+ // }
123
+ // }
124
+ return finalResults ;
125
+ } ;
126
+
79
127
/* DATA HANDLING HELPER FUNCTIONS */
80
128
const traverse = ( snapshot , data , snapshots , currTotalRender = 0 ) => {
81
129
if ( ! snapshot . children [ 0 ] ) return ;
@@ -100,24 +148,23 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
100
148
renderFrequency : 0 ,
101
149
totalRenderTime : 0 ,
102
150
rtid : '' ,
103
- props : { } ,
151
+ information : { } ,
104
152
} ;
105
153
if ( child . state !== 'stateless' ) data . componentData [ componentName ] . stateType = 'stateful' ;
106
154
}
107
155
// increment render frequencies
108
156
if ( renderTime > 0 ) {
109
- // console.log('what is the child', child);
110
- // console.log('por que?', data.componentData[componentName]);
111
157
data . componentData [ componentName ] . renderFrequency ++ ;
112
- } else {
113
- // console.log('what is the child', child);
114
- // console.log('we dont increment here', data.componentData[componentName], 'and the child', child);
115
158
}
159
+ // else {
160
+
161
+ // }
162
+
116
163
// add to total render time
117
164
data . componentData [ componentName ] . totalRenderTime += renderTime ;
118
165
// Get rtid for the hovering feature
119
166
data . componentData [ componentName ] . rtid = child . rtid ;
120
- data . componentData [ componentName ] . props = collectNodes ( snapshots , child . name ) ;
167
+ data . componentData [ componentName ] . information = collectNodes ( snapshots , child . name ) ;
121
168
traverse ( snapshot . children [ idx ] , data , snapshots , currTotalRender ) ;
122
169
} ) ;
123
170
// reassigns total render time to max render time
@@ -127,13 +174,10 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
127
174
128
175
// Retrieve snapshot series data from Chrome's local storage.
129
176
const allStorage = ( ) => {
130
- // const values = [];
131
177
// const keys = Object.keys(localStorage);
132
178
let values = localStorage . getItem ( 'project' )
133
- // values === null ? values = [] : values = JSON.parse(values) ;
134
179
values = values === null ? [ ] : JSON . parse ( values ) ;
135
180
// let i = keys.length;
136
- // console.log('allstorage keys', keys);
137
181
// while (i--) {
138
182
// const series = localStorage.getItem(keys[i]);
139
183
// values.push(JSON.parse(series));
@@ -160,7 +204,6 @@ const getPerfMetrics = (snapshots, snapshotsIds): {} => {
160
204
componentData : { } ,
161
205
maxTotalRender : 0 ,
162
206
} ;
163
- console . log ( 'show me all of the snapshots' , snapshots ) ;
164
207
snapshots . forEach ( ( snapshot , i ) => {
165
208
perfData . barStack . push ( { snapshotId : snapshotsIds [ i ] } ) ;
166
209
traverse ( snapshot , perfData , snapshots ) ;
@@ -201,10 +244,8 @@ const PerformanceVisx = (props: BarStackProps) => {
201
244
} ;
202
245
203
246
const renderComponentDetailsView = ( ) => {
204
- console . log ( 'show me snapshots' , snapshots )
205
- console . log ( 'what is heirarchy' , hierarchy ) ;
206
- console . log ( 'this is the info for rendering frequency' , data . componentData ) ;
207
247
if ( hierarchy ) {
248
+ console . log ( data . componentData )
208
249
return < RenderingFrequency data = { data . componentData } /> ;
209
250
}
210
251
return < div className = "noState" > { NO_STATE_MSG } </ div > ;
0 commit comments