1
1
/* eslint-disable guard-for-in */
2
- // * eslint-disable no-restricted-syntax */
2
+ /* eslint-disable no-restricted-syntax */
3
3
// @ts -nocheck
4
4
import React , { useState } from 'react' ;
5
+ import FormControlLabel from '@material-ui/core/FormControlLabel' ;
6
+ import { ParentSize } from '@visx/responsive' ;
5
7
import {
6
8
MemoryRouter as Router ,
7
9
Route ,
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' ;
16
20
// import snapshots from './snapshots';
21
+ import snapshots from './snapshots' ;
22
+
17
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
+
18
25
/* NOTES
19
26
Issue - Not fully compatible with recoil apps. Reference the recoil-todo-test.
20
27
Barstacks display inconsistently...however, almost always displays upon initial test app load or
@@ -23,14 +30,16 @@ However, cycling between updating state and then emptying sometimes fixes the st
23
30
to note - all snapshots do render (check HTML doc) within the chrome extension but they do
24
31
not display because height is not consistently passed to each bar. This side effect is only
25
32
seen in recoil apps...
26
- */
33
+ */
34
+
27
35
// typescript for PROPS from StateRoute.tsx
28
36
interface BarStackProps {
29
37
width : number ;
30
38
height : number ;
31
39
snapshots : [ ] ;
32
40
hierarchy : any ;
33
41
}
42
+
34
43
const makePropsPretty = data => {
35
44
const propsFormat = [ ] ;
36
45
const nestedObj = [ ] ;
@@ -52,6 +61,7 @@ const makePropsPretty = data => {
52
61
}
53
62
return propsFormat ;
54
63
} ;
64
+
55
65
const collectNodes = ( snaps , componentName ) => {
56
66
const componentsResult = [ ] ;
57
67
const renderResult = [ ] ;
@@ -100,6 +110,7 @@ const collectNodes = (snaps, componentName) => {
100
110
}
101
111
}
102
112
}
113
+
103
114
const finalResults = componentsResult . map ( ( e , index ) => {
104
115
const name = Object . keys ( e ) [ 0 ] ;
105
116
e [ name ] . rendertime = renderResult [ index ] ;
@@ -112,12 +123,15 @@ const collectNodes = (snaps, componentName) => {
112
123
}
113
124
return finalResults ;
114
125
} ;
126
+
115
127
/* DATA HANDLING HELPER FUNCTIONS */
116
128
const traverse = ( snapshot , data , snapshots , currTotalRender = 0 ) => {
117
129
if ( ! snapshot . children [ 0 ] ) return ;
130
+
118
131
// loop through snapshots
119
132
snapshot . children . forEach ( ( child , idx ) => {
120
133
const componentName = child . name + - [ idx + 1 ] ;
134
+
121
135
// Get component Rendering Time
122
136
const renderTime = Number (
123
137
Number . parseFloat ( child . componentData . actualDuration ) . toPrecision ( 5 ) ,
@@ -126,6 +140,7 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
126
140
currTotalRender += renderTime ;
127
141
// components as keys and set the value to their rendering time
128
142
data . barStack [ data . barStack . length - 1 ] [ componentName ] = renderTime ;
143
+
129
144
// Get component stateType
130
145
if ( ! data . componentData [ componentName ] ) {
131
146
data . componentData [ componentName ] = {
@@ -142,7 +157,9 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
142
157
data . componentData [ componentName ] . renderFrequency ++ ;
143
158
}
144
159
// else {
160
+
145
161
// }
162
+
146
163
// add to total render time
147
164
data . componentData [ componentName ] . totalRenderTime += renderTime ;
148
165
// Get rtid for the hovering feature
@@ -154,17 +171,21 @@ const traverse = (snapshot, data, snapshots, currTotalRender = 0) => {
154
171
data . maxTotalRender = Math . max ( currTotalRender , data . maxTotalRender ) ;
155
172
return data ;
156
173
} ;
174
+
157
175
// Retrieve snapshot series data from Chrome's local storage.
158
176
const allStorage = ( ) => {
159
177
const values = [ ] ;
160
178
const keys = Object . keys ( localStorage ) ;
161
179
let i = keys . length ;
180
+
181
+
162
182
while ( i -- ) {
163
183
const series = localStorage . getItem ( keys [ i ] ) ;
164
184
values . push ( JSON . parse ( series ) ) ;
165
185
}
166
186
return values ;
167
187
} ;
188
+
168
189
// Gets snapshot Ids for the regular bar graph view.
169
190
const getSnapshotIds = ( obj , snapshotIds = [ ] ) : string [ ] => {
170
191
snapshotIds . push ( `${ obj . name } .${ obj . branch } ` ) ;
@@ -175,6 +196,7 @@ const getSnapshotIds = (obj, snapshotIds = []): string[] => {
175
196
}
176
197
return snapshotIds ;
177
198
} ;
199
+
178
200
// Returns array of snapshot objs each with components and corresponding render times.
179
201
const getPerfMetrics = ( snapshots , snapshotsIds ) : { } => {
180
202
const perfData = {
@@ -188,6 +210,7 @@ const getPerfMetrics = (snapshots, snapshotsIds): {} => {
188
210
} ) ;
189
211
return perfData ;
190
212
} ;
213
+
191
214
/* EXPORT COMPONENT */
192
215
const PerformanceVisx = ( props : BarStackProps ) => {
193
216
// hook used to dispatch onhover action in rect
@@ -200,6 +223,7 @@ const PerformanceVisx = (props: BarStackProps) => {
200
223
const [ comparisonData , setComparisonData ] = useState ( ) ;
201
224
const NO_STATE_MSG = 'No state change detected. Trigger an event to change state' ;
202
225
const data = getPerfMetrics ( snapshots , getSnapshotIds ( hierarchy ) ) ;
226
+
203
227
const renderComparisonBargraph = ( ) => {
204
228
if ( hierarchy ) {
205
229
return (
@@ -212,17 +236,20 @@ const PerformanceVisx = (props: BarStackProps) => {
212
236
) ;
213
237
}
214
238
} ;
239
+
215
240
const renderBargraph = ( ) => {
216
241
if ( hierarchy ) {
217
242
return < BarGraph data = { data } width = { width } height = { height } /> ;
218
243
}
219
244
} ;
245
+
220
246
const renderComponentDetailsView = ( ) => {
221
247
if ( hierarchy ) {
222
248
return < RenderingFrequency data = { data . componentData } /> ;
223
249
}
224
250
return < div className = "noState" > { NO_STATE_MSG } </ div > ;
225
251
} ;
252
+
226
253
return (
227
254
< Router >
228
255
< div className = "performance-nav-bar-container" >
@@ -252,6 +279,7 @@ const PerformanceVisx = (props: BarStackProps) => {
252
279
Component Details
253
280
</ NavLink >
254
281
</ div >
282
+
255
283
< Switch >
256
284
< Route path = "/comparison" render = { renderComparisonBargraph } />
257
285
< Route path = "/componentdetails" render = { renderComponentDetailsView } />
@@ -260,4 +288,5 @@ const PerformanceVisx = (props: BarStackProps) => {
260
288
</ Router >
261
289
) ;
262
290
} ;
263
- export default PerformanceVisx ;
291
+
292
+ export default PerformanceVisx ;
0 commit comments