Skip to content

Commit cf74433

Browse files
committed
refactor(core): Improve code readability and optimization
1 parent 5fd5223 commit cf74433

File tree

6 files changed

+22
-29
lines changed

6 files changed

+22
-29
lines changed

metro.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
2-
export * from "./dist/core/index.js"
1+
export * from './dist/core/index.js';

native.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
2-
export * from "./dist/native.js"
1+
export * from './dist/native.js';

pnpm-lock.yaml

Lines changed: 6 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import type * as React from 'react';
33
import { instrument, type Render } from './instrumentation/index';
44
import { playGeigerClickSound } from './web/geiger';
55
import { createStore } from './utils';
6-
76
import { createPerfObserver } from './web/perf-observer';
87
import { createOverlay } from './web';
98
import { logIntro } from './web/log';
109
import { createToolbar } from './web/toolbar';
1110
import {
12-
PendingOutline,
13-
ActiveOutline,
11+
type PendingOutline,
12+
type ActiveOutline,
1413
getOutline,
1514
flushOutlines,
1615
} from './web/outline';
@@ -216,9 +215,11 @@ export const start = () => {
216215
if (report) {
217216
report.renders.push(render);
218217
}
218+
const count = report?.count ?? 0;
219+
const time = report?.time ?? 0;
219220
ReactScanInternals.reportData[render.name] = {
220-
count: (report?.count ?? 0) + render.count,
221-
time: (report?.time ?? 0) + render.time,
221+
count: count + render.count,
222+
time: time + render.time,
222223
renders: report?.renders || [],
223224
};
224225
}

src/core/native/plugins/metro.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
type TransformParams = {
1+
interface TransformParams {
22
src: string;
33
filename: string;
44
options?: any;
5-
};
5+
}
66

7-
type TransformResult = {
7+
interface TransformResult {
88
code: string;
99
map?: any;
10-
};
10+
}
1111

12+
// eslint-disable-next-line @typescript-eslint/no-var-requires
1213
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
1314

1415
const defaultConfig = getDefaultConfig(__dirname);
@@ -21,15 +22,11 @@ const config = {
2122

2223
if (filename.includes('node_modules/react-scan/dist/core/native/')) {
2324
return {
24-
code: `export const ReactNativeScanEntryPoint = () => {
25-
/* NOOP */
26-
return null;
27-
};`,
25+
code: `export const ReactNativeScanEntryPoint = () => null;`,
2826
};
2927
}
3028

3129
return { code: src };
3230
},
3331
};
3432
module.exports = mergeConfig(defaultConfig, config);
35-

src/core/web/outline.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { type Fiber } from 'react-reconciler';
22
import { getNearestHostFiber } from '../instrumentation/fiber';
33
import type { Render } from '../instrumentation/index';
4-
import { Measurement, ReactScanInternals } from '../index';
4+
import { type Measurement, ReactScanInternals } from '../index';
55
import { getLabelText } from '../utils';
6-
import { isOutlineUnstable, onIdle, throttle } from './utils';
6+
import { isOutlineUnstable, throttle } from './utils';
77
import { log } from './log';
88
import { recalcOutlineColor } from './perf-observer';
99
// import { genId } from '../native/instrument';

0 commit comments

Comments
 (0)