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