Skip to content

Commit 7ad02b9

Browse files
JeanMecheAndrewKushnir
authored andcommitted
refactor(devtools): fix parameter matching. (angular#64260)
Adding some typing to infer the expected types and drop the usages of `arguments` which isn't really typesafe. The argument mis-match didn't result in an issue because they didn't end up being used futher down the line. fix 63973 PR Close angular#64260
1 parent 88a15be commit 7ad02b9

File tree

2 files changed

+46
-36
lines changed

2 files changed

+46
-36
lines changed

devtools/projects/ng-devtools-backend/src/lib/hooks/capture.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const getHooks = (onFrame: (frame: ProfilerFrame) => void): Partial<Hooks> => {
143143
directive: any,
144144
hookName: keyof LifecycleProfile,
145145
node: Node,
146-
__: number,
146+
id: number,
147147
isComponent: boolean,
148148
): void {
149149
startEvent(timeStartMap, directive, hookName);
@@ -181,6 +181,7 @@ const getHooks = (onFrame: (frame: ProfilerFrame) => void): Partial<Hooks> => {
181181
componentOrDirective: any,
182182
outputName: string,
183183
node: Node,
184+
id: number | undefined,
184185
isComponent: boolean,
185186
): void {
186187
startEvent(timeStartMap, componentOrDirective, outputName);

devtools/projects/ng-devtools-backend/src/lib/hooks/profiler/shared.ts

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ type OutputStartHook = (
6161
componentOrDirective: any,
6262
outputName: string,
6363
node: Node,
64+
id: number | undefined,
6465
isComponent: boolean,
6566
) => void;
6667
type OutputEndHook = (
6768
componentOrDirective: any,
6869
outputName: string,
6970
node: Node,
71+
id: number | undefined,
7072
isComponent: boolean,
7173
) => void;
7274

@@ -112,119 +114,126 @@ export abstract class Profiler {
112114
/** @internal */
113115
protected _onCreate(
114116
_: any,
115-
__: Node,
117+
hook: Node,
116118
id: number | undefined,
117-
___: boolean,
119+
node: boolean,
118120
position: ElementPosition | undefined,
119121
): void {
120122
if (id === undefined || position === undefined) {
121123
return;
122124
}
123-
this._invokeCallback('onCreate', arguments);
125+
this._invokeCallback('onCreate', [_, hook, id, node, position]);
124126
}
125127

126128
/** @internal */
127129
protected _onDestroy(
128130
_: any,
129-
__: Node,
131+
hook: Node,
130132
id: number | undefined,
131-
___: boolean,
133+
node: boolean,
132134
position: ElementPosition | undefined,
133135
): void {
134136
if (id === undefined || position === undefined) {
135137
return;
136138
}
137-
this._invokeCallback('onDestroy', arguments);
139+
this._invokeCallback('onDestroy', [_, hook, id, node, position]);
138140
}
139141

140142
/** @internal */
141143
protected _onChangeDetectionStart(
142144
_: any,
143-
__: Node,
145+
hook: Node,
144146
id: number | undefined,
145147
position: ElementPosition | undefined,
146148
): void {
147149
if (id === undefined || position === undefined) {
148150
return;
149151
}
150-
this._invokeCallback('onChangeDetectionStart', arguments);
152+
this._invokeCallback('onChangeDetectionStart', [_, hook, id, position]);
151153
}
152154

153155
/** @internal */
154156
protected _onChangeDetectionEnd(
155157
_: any,
156-
__: Node,
158+
hook: Node,
157159
id: number | undefined,
158160
position: ElementPosition | undefined,
159161
): void {
160162
if (id === undefined || position === undefined) {
161163
return;
162164
}
163-
this._invokeCallback('onChangeDetectionEnd', arguments);
165+
this._invokeCallback('onChangeDetectionEnd', [_, hook, id, position]);
164166
}
165167

166168
/** @internal */
167169
protected _onLifecycleHookStart(
168-
_: any,
169-
__: keyof LifecycleProfile | 'unknown',
170-
___: Node,
170+
componentOrDirective: any,
171+
hook: keyof LifecycleProfile | 'unknown',
172+
node: Node,
171173
id: number | undefined,
172-
____: boolean,
174+
isComponent: boolean,
173175
): void {
174-
if (id === undefined) {
176+
if (id === undefined || hook === 'unknown') {
175177
return;
176178
}
177-
this._invokeCallback('onLifecycleHookStart', arguments);
179+
const a = arguments;
180+
this._invokeCallback('onLifecycleHookStart', [
181+
componentOrDirective,
182+
hook,
183+
node,
184+
id,
185+
isComponent,
186+
]);
178187
}
179188

180189
/** @internal */
181190
protected _onLifecycleHookEnd(
182-
_: any,
183-
__: keyof LifecycleProfile | 'unknown',
184-
___: Node,
191+
componentOrDirective: any,
192+
hook: keyof LifecycleProfile | 'unknown',
193+
node: Node,
185194
id: number | undefined,
186-
____: boolean,
195+
isComponent: boolean,
187196
): void {
188-
if (id === undefined) {
197+
if (id === undefined || hook === 'unknown') {
189198
return;
190199
}
191-
this._invokeCallback('onLifecycleHookEnd', arguments);
200+
this._invokeCallback('onLifecycleHookEnd', [componentOrDirective, hook, node, id, isComponent]);
192201
}
193202

194203
/** @internal */
195204
protected _onOutputStart(
196-
_: any,
197-
__: string,
198-
___: Node,
205+
componentOrDirective: any,
206+
hook: string,
207+
node: Node,
199208
id: number | undefined,
200-
____: boolean,
209+
isComponent: boolean,
201210
): void {
202211
if (id === undefined) {
203212
return;
204213
}
205-
this._invokeCallback('onOutputStart', arguments);
214+
this._invokeCallback('onOutputStart', [componentOrDirective, hook, node, id, isComponent]);
206215
}
207216

208217
/** @internal */
209218
protected _onOutputEnd(
210-
_: any,
211-
__: string,
212-
___: Node,
219+
componentOrDirective: any,
220+
hook: string,
221+
node: Node,
213222
id: number | undefined,
214-
____: boolean,
223+
isComponent: boolean,
215224
): void {
216225
if (id === undefined) {
217226
return;
218227
}
219-
this._invokeCallback('onOutputEnd', arguments);
228+
this._invokeCallback('onOutputEnd', [componentOrDirective, hook, node, id, isComponent]);
220229
}
221230

222231
/** @internal */
223-
private _invokeCallback(name: keyof Hooks, args: IArguments): void {
232+
private _invokeCallback<K extends keyof Hooks>(name: K, args: Parameters<Hooks[K]>): void {
224233
this._hooks.forEach((config) => {
225-
const cb = config[name];
234+
const cb = (config as Hooks)[name];
226235
if (typeof cb === 'function') {
227-
(cb as any).apply(null, args);
236+
(cb as Function).apply(null, args);
228237
}
229238
});
230239
}

0 commit comments

Comments
 (0)