-
Notifications
You must be signed in to change notification settings - Fork 54
/
parseMeasures.js
42 lines (38 loc) · 1.06 KB
/
parseMeasures.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
This function returns the component name and phase name from the measure name (returned from React performance data).
This may break if React changes the mark name (measure name).
*/
const getComponentAndPhaseName = measure => {
if (measure.name.includes('⚛')) {
let index = measure.name.split('⚛ ').join('')
// "App [mount]"
if (/\[\w+\]/.test(index)) {
const [componentName, phase] = index.split(' ')
return {
componentName,
phase
}
} else if (/\w+\.\w+/.test(index)) {
// App.componentWillMount
const [componentName, lifecycle] = index.split('.')
return {
componentName,
phase: lifecycle
}
} else {
return null
}
} else if (measure.name.includes('⛔')) {
let index = measure.name.split('⛔ ').join('')
if (/\w+\.\w+/.test(index)) {
return {
componentName: index.split('.')[0],
phase: index.split('.')[1].split(' Warning:')[0]
}
} else {
return null
}
}
return null
}
export { getComponentAndPhaseName }