Skip to content

Commit

Permalink
ref: Change React Profiler prop names:
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed Jun 25, 2020
1 parent 1edad85 commit 85fb8b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions packages/react/src/profiler.tsx
Expand Up @@ -104,8 +104,8 @@ class Profiler extends React.Component<ProfilerProps> {

public static defaultProps: Partial<ProfilerProps> = {
disabled: false,
hasRenderSpan: true,
hasUpdateSpan: true,
includeRender: true,
includeUpdates: true,
};

public constructor(props: ProfilerProps) {
Expand All @@ -130,11 +130,11 @@ class Profiler extends React.Component<ProfilerProps> {
this.mountActivity = null;
}

public componentDidUpdate({ updateProps, hasUpdateSpan = true }: ProfilerProps): void {
public componentDidUpdate({ updateProps, includeUpdates = true }: ProfilerProps): void {
// Only generate an update span if hasUpdateSpan is true, if there is a valid mountSpan,
// and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.
// We are just trying to give baseline clues for further investigation.
if (hasUpdateSpan && this.mountSpan && updateProps !== this.props.updateProps) {
if (includeUpdates && this.mountSpan && updateProps !== this.props.updateProps) {
// See what props haved changed between the previous props, and the current props. This is
// set as data on the span. We just store the prop keys as the values could be potenially very large.
const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);
Expand All @@ -158,9 +158,9 @@ class Profiler extends React.Component<ProfilerProps> {
// If a component is unmounted, we can say it is no longer on the screen.
// This means we can finish the span representing the component render.
public componentWillUnmount(): void {
const { name, hasRenderSpan = true } = this.props;
const { name, includeRender = true } = this.props;

if (this.mountSpan && hasRenderSpan) {
if (this.mountSpan && includeRender) {
// If we were able to obtain the spanId of the mount activity, we should set the
// next activity as a child to the component mount activity.
this.mountSpan.startChild({
Expand Down
4 changes: 2 additions & 2 deletions packages/react/test/profiler.test.tsx
Expand Up @@ -120,7 +120,7 @@ describe('withProfiler', () => {
});

it('is not created if hasRenderSpan is false', () => {
const ProfiledComponent = withProfiler(() => <h1>Testing</h1>, { hasRenderSpan: false });
const ProfiledComponent = withProfiler(() => <h1>Testing</h1>, { includeRender: false });
expect(mockStartChild).toHaveBeenCalledTimes(0);

const component = render(<ProfiledComponent />);
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('withProfiler', () => {

it('does not get created if hasUpdateSpan is false', () => {
const ProfiledComponent = withProfiler((props: { num: number }) => <div>{props.num}</div>, {
hasUpdateSpan: false,
includeUpdates: false,
});
const { rerender } = render(<ProfiledComponent num={0} />);
expect(mockStartChild).toHaveBeenCalledTimes(0);
Expand Down

0 comments on commit 85fb8b0

Please sign in to comment.