Skip to content

Commit feeb6ba

Browse files
committed
ref(react): Use class properties
1 parent f313d6b commit feeb6ba

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

packages/react/src/profiler.tsx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,43 +62,35 @@ interface ProfilerProps {
6262
componentDisplayName?: string;
6363
}
6464

65-
interface ProfilerState {
66-
activity: number | null;
67-
}
65+
class Profiler extends React.Component<ProfilerProps> {
66+
public activity: number | null;
6867

69-
class Profiler extends React.Component<ProfilerProps, ProfilerState> {
7068
public constructor(props: ProfilerProps) {
7169
super(props);
7270

7371
const { componentDisplayName = UNKNOWN_COMPONENT } = this.props;
7472

75-
this.state = {
76-
activity: getInitActivity(componentDisplayName),
77-
};
73+
this.activity = getInitActivity(componentDisplayName);
7874
}
7975

8076
public componentDidMount(): void {
81-
if (this.state.activity) {
82-
afterNextFrame(this.finishProfile);
83-
}
77+
afterNextFrame(this.finishProfile);
8478
}
8579

8680
public componentWillUnmount(): void {
87-
if (this.state.activity) {
88-
afterNextFrame(this.finishProfile);
89-
}
81+
afterNextFrame(this.finishProfile);
9082
}
9183

9284
public finishProfile = () => {
93-
if (!this.state.activity) {
85+
if (!this.activity) {
9486
return;
9587
}
9688

9789
const tracingIntegration = getCurrentHub().getIntegration(TRACING_GETTER);
9890
if (tracingIntegration !== null) {
9991
// tslint:disable-next-line:no-unsafe-any
100-
(tracingIntegration as any).constructor.popActivity(this.state.activity);
101-
this.setState({ activity: null });
92+
(tracingIntegration as any).constructor.popActivity(this.activity);
93+
this.activity = null;
10294
}
10395
};
10496

packages/react/test/profiler.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('withProfiler', () => {
3434

3535
describe('Tracing Integration', () => {
3636
beforeEach(() => {
37+
jest.useFakeTimers();
3738
mockPushActivity.mockClear();
3839
mockPopActivity.mockClear();
3940
});
@@ -46,6 +47,8 @@ describe('withProfiler', () => {
4647
const profiler = create(<ProfiledComponent />);
4748
profiler.unmount();
4849

50+
jest.runAllTimers();
51+
4952
expect(mockPopActivity).toHaveBeenCalledTimes(1);
5053
expect(mockPopActivity).toHaveBeenLastCalledWith(1);
5154
});

0 commit comments

Comments
 (0)