Skip to content

Commit 17636b6

Browse files
committed
refactor: impl feedback
1 parent fea5745 commit 17636b6

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

packages/utils/src/lib/profiler/profiler.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
DevToolsColor,
1515
EntryMeta,
1616
} from '../user-timing-extensibility-api.type.js';
17-
import { PROFILER_ENABLED } from './constants.js';
17+
import { PROFILER_ENABLED_ENV_VAR } from './constants.js';
1818

1919
/**
2020
* Configuration options for creating a Profiler instance.
@@ -48,9 +48,8 @@ export type MarkerOptions = EntryMeta & { color?: DevToolsColor };
4848
* @property color - Default color for track entries
4949
* @property tracks - Custom track configurations merged with defaults
5050
*/
51-
export type ProfilerOptions<
52-
T extends ActionTrackConfigs = Record<string, ActionTrackEntryPayload>,
53-
> = ProfilerMeasureOptions<T>;
51+
export type ProfilerOptions<T extends ActionTrackConfigs = ActionTrackConfigs> =
52+
ProfilerMeasureOptions<T>;
5453

5554
/**
5655
* Performance profiler that creates structured timing measurements with Chrome DevTools Extensibility API payloads.
@@ -81,12 +80,12 @@ export class Profiler<T extends ActionTrackConfigs> {
8180
const { tracks, prefix, enabled, ...defaults } = options;
8281
const dataType = 'track-entry';
8382

84-
this.#enabled = enabled ?? isEnvVarEnabled(PROFILER_ENABLED);
85-
this.defaults = { ...defaults, dataType };
83+
this.#enabled = enabled ?? isEnvVarEnabled(PROFILER_ENABLED_ENV_VAR);
84+
this.#defaults = { ...defaults, dataType };
8685
this.tracks = tracks
8786
? setupTracks({ ...defaults, dataType }, tracks)
8887
: undefined;
89-
this.ctxOf = measureCtx({
88+
this.#ctxOf = measureCtx({
9089
...defaults,
9190
dataType,
9291
prefix,
@@ -102,7 +101,7 @@ export class Profiler<T extends ActionTrackConfigs> {
102101
* @param enabled - Whether profiling should be enabled
103102
*/
104103
setEnabled(enabled: boolean): void {
105-
process.env[PROFILER_ENABLED] = `${enabled}`;
104+
process.env[PROFILER_ENABLED_ENV_VAR] = `${enabled}`;
106105
this.#enabled = enabled;
107106
}
108107

@@ -150,7 +149,7 @@ export class Profiler<T extends ActionTrackConfigs> {
150149
asOptions(
151150
markerPayload({
152151
// marker only takes default color, no TrackMeta
153-
...(this.defaults.color ? { color: this.defaults.color } : {}),
152+
...(this.#defaults.color ? { color: this.#defaults.color } : {}),
154153
...opt,
155154
}),
156155
),
@@ -178,7 +177,7 @@ export class Profiler<T extends ActionTrackConfigs> {
178177
return work();
179178
}
180179

181-
const { start, success, error } = this.ctxOf(event, options);
180+
const { start, success, error } = this.#ctxOf(event, options);
182181
start();
183182
try {
184183
const r = work();
@@ -215,7 +214,7 @@ export class Profiler<T extends ActionTrackConfigs> {
215214
return await work();
216215
}
217216

218-
const { start, success, error } = this.ctxOf(event, options);
217+
const { start, success, error } = this.#ctxOf(event, options);
219218
start();
220219
try {
221220
const r = await work();

0 commit comments

Comments
 (0)