Skip to content
18 changes: 0 additions & 18 deletions packages/react-devtools-shared/src/devtools/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
* @flow
*/

import {
ElementTypeForwardRef,
ElementTypeMemo,
} from 'react-devtools-shared/src/types';

import type {Element} from './views/Components/types';
import type Store from './store';

Expand All @@ -30,19 +25,6 @@ export function printElement(element: Element, includeWeight: boolean = false) {
if (element.hocDisplayNames !== null) {
hocDisplayNames = [...element.hocDisplayNames];
}
if (element.type === ElementTypeMemo) {
if (hocDisplayNames === null) {
hocDisplayNames = ['Memo'];
} else {
hocDisplayNames.push('Memo');
}
} else if (element.type === ElementTypeForwardRef) {
if (hocDisplayNames === null) {
hocDisplayNames = ['ForwardRef'];
} else {
hocDisplayNames.push('ForwardRef');
}
}
Comment thread
bvaughn marked this conversation as resolved.

const hocs =
hocDisplayNames === null ? '' : ` [${hocDisplayNames.join('][')}]`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

import * as React from 'react';
import {Fragment} from 'react';
import {
ElementTypeMemo,
ElementTypeForwardRef,
} from 'react-devtools-shared/src/types';
import styles from './Badge.css';

import type {ElementType} from 'react-devtools-shared/src/types';
Expand All @@ -21,35 +17,24 @@ type Props = {|
className?: string,
hocDisplayNames: Array<string> | null,
type: ElementType,
children: React$Node,
|};

export default function Badge({className, hocDisplayNames, type}: Props) {
let hocDisplayName = null;
export default function Badge({
className,
hocDisplayNames,
type,
children,
}: Props) {
let totalBadgeCount = 0;
let typeLabel = null;

if (hocDisplayNames !== null) {
hocDisplayName = hocDisplayNames[0];
totalBadgeCount += hocDisplayNames.length;
}

if (type === ElementTypeMemo) {
typeLabel = 'Memo';
totalBadgeCount++;
} else if (type === ElementTypeForwardRef) {
typeLabel = 'ForwardRef';
totalBadgeCount++;
}

if (hocDisplayNames === null && typeLabel === null) {
return null;
}

return (
<Fragment>
<div className={`${styles.Badge} ${className || ''}`}>
{hocDisplayName || typeLabel}
</div>
<div className={`${styles.Badge} ${className || ''}`}>{children}</div>
{totalBadgeCount > 1 && (
<div className={styles.ExtraLabel}>+{totalBadgeCount - 1}</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,17 @@ export default function ElementView({data, index, style}: Props) {
"
</Fragment>
)}
<Badge
className={styles.Badge}
hocDisplayNames={hocDisplayNames}
type={type}
/>
{hocDisplayNames !== null ? (
<Badge
className={styles.Badge}
hocDisplayNames={hocDisplayNames}
type={type}>
<DisplayName
displayName={hocDisplayNames[0]}
id={((id: any): number)}
/>
</Badge>
) : null}
</div>
</div>
);
Expand Down
8 changes: 6 additions & 2 deletions packages/react-devtools-shared/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@ export function separateDisplayNameAndHOCs(

switch (type) {
case ElementTypeClass:
case ElementTypeForwardRef:
case ElementTypeFunction:
case ElementTypeMemo:
if (displayName.indexOf('(') >= 0) {
const matches = displayName.match(/[^()]+/g);
if (matches != null) {
Expand All @@ -271,6 +269,12 @@ export function separateDisplayNameAndHOCs(
}
}
break;
case ElementTypeForwardRef:
hocDisplayNames = ['ForwardRef'];
break;
case ElementTypeMemo:
hocDisplayNames = ['Memo'];
break;
default:
break;
}
Expand Down