Skip to content

Commit 28b8ef0

Browse files
committed
ref(utils): Change addInstrumentationHandler to take reg args
Passing in an object is not necessary as there is always going to be two arguments required. We can just convert this to explicitly passing the options, it saves on bundle size. In addition, we can remove the guards around `type` and `callback` because addInstrumentationHandler is an internally used function, so Typescript and our test suite should handle the function getting called with arguments of the correct type.
1 parent 1082ad6 commit 28b8ef0

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

packages/utils/src/instrument.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ import { supportsHistory, supportsNativeFetch } from './supports';
1212

1313
const global = getGlobalObject<Window>();
1414

15-
/** Object describing handler that will be triggered for a given `type` of instrumentation */
16-
interface InstrumentHandler {
17-
type: InstrumentHandlerType;
18-
callback: InstrumentHandlerCallback;
19-
}
2015
type InstrumentHandlerType =
2116
| 'console'
2217
| 'dom'
@@ -82,13 +77,10 @@ function instrument(type: InstrumentHandlerType): void {
8277
* Use at your own risk, this might break without changelog notice, only used internally.
8378
* @hidden
8479
*/
85-
export function addInstrumentationHandler(handler: InstrumentHandler): void {
86-
if (!handler || typeof handler.type !== 'string' || typeof handler.callback !== 'function') {
87-
return;
88-
}
89-
handlers[handler.type] = handlers[handler.type] || [];
90-
(handlers[handler.type] as InstrumentHandlerCallback[]).push(handler.callback);
91-
instrument(handler.type);
80+
export function addInstrumentationHandler(type: InstrumentHandlerType, callback: InstrumentHandlerCallback): void {
81+
handlers[type] = handlers[type] || [];
82+
(handlers[type] as InstrumentHandlerCallback[]).push(callback);
83+
instrument(type);
9284
}
9385

9486
/** JSDoc */

0 commit comments

Comments
 (0)