Skip to content

Commit 648c3ed

Browse files
committed
feat: enhance type definitions and improve memoization in ConsolePanelItem and NetworkPanelItem
1 parent 512c5a8 commit 648c3ed

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

src/ui/Xenon.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ import { type DebuggerState } from '../types';
1010
import { Bubble, IndexedStack, Panel, SearchBar } from './components';
1111

1212
namespace Xenon {
13-
interface Methods {
13+
export interface Methods {
1414
isVisible(): boolean;
1515
show(): void;
1616
hide(): void;
1717
}
1818

19-
interface Props {
19+
export interface Props {
20+
children: ReactNode;
21+
/**
22+
* If true, completely disables the debugger by rendering only the children components without any debugging functionality.
23+
* @default false
24+
*/
25+
disabled?: boolean;
2026
/**
2127
* Determines whether the network inspector is automatically enabled upon initialization.
2228
* @default true
@@ -45,23 +51,14 @@ namespace Xenon {
4551
includeDomains?: string[];
4652
}
4753

48-
interface WrapperProps extends Props {
49-
/**
50-
* If true, completely disables the debugger by rendering only the children components without any debugging functionality.
51-
* @default false
52-
*/
53-
disabled?: boolean;
54-
children: ReactNode;
55-
}
56-
5754
enableMapSet();
5855
const ref = createRef<Methods>();
5956

6057
/**
6158
* Checks whether the debugger is currently visible.
6259
* @returns `true` if the debugger is currently visible, otherwise `false`.
6360
*/
64-
export const isVisible = () => ref.current?.isVisible() ?? false;
61+
export const isVisible = (): boolean => ref.current?.isVisible() ?? false;
6562

6663
/**
6764
* Makes the debugger visible. If it is already visible, this method has no additional effect.
@@ -75,14 +72,14 @@ namespace Xenon {
7572
*/
7673
export const hide = (): void => ref.current?.hide();
7774

78-
const Debugger = memo(
75+
const Debugger = memo<Omit<Props, 'children' | 'disabled'>>(
7976
({
8077
autoInspectNetworkEnabled = true,
8178
autoInspectConsoleEnabled = true,
8279
bubbleSize = 40,
8380
idleBubbleOpacity = 0.5,
8481
includeDomains,
85-
}: Props) => {
82+
}) => {
8683
const dimensions = useWindowDimensions();
8784

8885
const [debuggerState, setDebuggerState] = useImmer<DebuggerState>({
@@ -142,9 +139,15 @@ namespace Xenon {
142139
</MainContext.Provider>
143140
);
144141
},
142+
(prevProps, nextProps) =>
143+
prevProps.autoInspectNetworkEnabled === nextProps.autoInspectNetworkEnabled &&
144+
prevProps.autoInspectConsoleEnabled === nextProps.autoInspectConsoleEnabled &&
145+
prevProps.bubbleSize === nextProps.bubbleSize &&
146+
prevProps.idleBubbleOpacity === nextProps.idleBubbleOpacity &&
147+
JSON.stringify(prevProps.includeDomains) === JSON.stringify(nextProps.includeDomains),
145148
);
146149

147-
export function Wrapper({ disabled = false, children, ...props }: WrapperProps): JSX.Element {
150+
export function Wrapper({ disabled = false, children, ...props }: Props): JSX.Element {
148151
if (disabled) return children as JSX.Element;
149152

150153
return (

src/ui/components/items/ConsolePanelItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ const ConsolePanelItem = memo<ConsolePanelItemProps>(
2222
</Touchable>
2323
);
2424
},
25-
(prevProps, nextProps) => {
26-
return prevProps.type === nextProps.type && prevProps.values === nextProps.values;
27-
},
25+
(prevProps, nextProps) =>
26+
prevProps.type === nextProps.type &&
27+
JSON.stringify(prevProps.values) === JSON.stringify(nextProps.values),
2828
);
2929

3030
const styles = StyleSheet.create({

src/ui/components/items/NetworkPanelItem.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,12 @@ const NetworkPanelItem = memo<NetworkPanelItemProps>(
101101
</View>
102102
);
103103
},
104-
(prevProps, nextProps) => {
105-
return (
106-
prevProps.method === nextProps.method &&
107-
prevProps.name === nextProps.name &&
108-
prevProps.startTime === nextProps.startTime &&
109-
prevProps.endTime === nextProps.endTime &&
110-
prevProps.status === nextProps.status
111-
);
112-
},
104+
(prevProps, nextProps) =>
105+
prevProps.method === nextProps.method &&
106+
prevProps.name === nextProps.name &&
107+
prevProps.startTime === nextProps.startTime &&
108+
prevProps.endTime === nextProps.endTime &&
109+
prevProps.status === nextProps.status,
113110
);
114111

115112
const styles = StyleSheet.create({

0 commit comments

Comments
 (0)