-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy pathshouldTrack.js
48 lines (40 loc) · 1.16 KB
/
shouldTrack.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
43
44
45
46
47
48
import wdyrStore from './wdyrStore';
import { isMemoComponent } from './utils';
import getDisplayName from './getDisplayName';
function shouldInclude(displayName) {
return (
wdyrStore.options.include &&
wdyrStore.options.include.length > 0 &&
wdyrStore.options.include.some(regex => regex.test(displayName))
);
}
function shouldExclude(displayName) {
return (
wdyrStore.options.exclude &&
wdyrStore.options.exclude.length > 0 &&
wdyrStore.options.exclude.some(regex => regex.test(displayName))
);
}
export default function shouldTrack(Component, { isHookChange }) {
const displayName = getDisplayName(Component);
if (shouldExclude(displayName)) {
return false;
}
if (Component.whyDidYouRender === false) {
return false;
}
if (isHookChange && (
Component.whyDidYouRender && Component.whyDidYouRender.trackHooks === false
)) {
return false;
}
return !!(
Component.whyDidYouRender || (
wdyrStore.options.trackAllPureComponents && (
(Component && Component.prototype instanceof wdyrStore.React.PureComponent) ||
isMemoComponent(Component)
)
) ||
shouldInclude(displayName)
);
}