Skip to content

Commit 841562a

Browse files
committed
icon computation without mutable variables
1 parent 0d3b6cc commit 841562a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/components/icon/icon.tsx

+11-5
Original file line numberDiff line numberDiff line change
@@ -625,21 +625,27 @@ export class OuiIcon extends PureComponent<OuiIconProps, State> {
625625
let initialIcon;
626626
let isLoading = false;
627627

628-
// Category 1: cached oui icons
628+
// Define helper function
629+
const getIconAndLoadingStatus = (type: any) => {
630+
// Category 1: cached oui icons
629631
if (isCachedIcon(type)) {
630-
initialIcon = iconComponentCache[type as string];
632+
return { icon: iconComponentCache[type as string], isLoading: false };
631633
// Category 2: URL (relative, absolute)
632634
} else if (isUrl(type)) {
633-
initialIcon = type;
635+
return { icon: type, isLoading: false };
634636
// Category 3: non-cached oui icon or new icon
635637
} else if (typeof type === 'string') {
636-
isLoading = true;
637638
this.loadIconComponent(type as OuiIconType);
639+
return { icon: undefined, isLoading: true };
638640
} else {
639641
// Category 4: custom icon component
640-
initialIcon = type;
641642
this.onIconLoad();
643+
return { icon: type, isLoading: false };
642644
}
645+
};
646+
647+
// Use the helper function
648+
const { icon: initialIcon, isLoading } = getIconAndLoadingStatus(type);
643649

644650
this.state = {
645651
icon: initialIcon,

0 commit comments

Comments
 (0)