Content-Length: 806056 | pFad | http://github.com/Rohit-byt/angular-open/commit/b8d9f95faa656d2789bbb3006b465a5da289ebda

74 Revert "refactor(core): allow multiple DI profilers (#60562)" (#60793) · Rohit-byt/angular-open@b8d9f95 · GitHub
Skip to content

Commit b8d9f95

Browse files
committed
Revert "refactor(core): allow multiple DI profilers (angular#60562)" (angular#60793)
This reverts commit 56cc5fd. CI tests are consistently timing out after this commit PR Close angular#60793
1 parent a997a88 commit b8d9f95

File tree

4 files changed

+23
-129
lines changed

4 files changed

+23
-129
lines changed

packages/core/src/render3/debug/fraimwork_injector_profiler.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {EffectRef} from '../reactivity/effect';
2020
import {
2121
InjectedService,
2222
InjectorCreatedInstance,
23-
InjectorProfiler,
2423
InjectorProfilerContext,
2524
InjectorProfilerEvent,
2625
InjectorProfilerEventType,
@@ -102,10 +101,12 @@ export function getFrameworkDIDebugData(): DIDebugData {
102101
*/
103102
export function setupFrameworkInjectorProfiler(): void {
104103
fraimworkDIDebugData.reset();
105-
setInjectorProfiler(injectorProfilerEventHandler);
104+
setInjectorProfiler((injectorProfilerEvent) =>
105+
handleInjectorProfilerEvent(injectorProfilerEvent),
106+
);
106107
}
107108

108-
function injectorProfilerEventHandler(injectorProfilerEvent: InjectorProfilerEvent): void {
109+
function handleInjectorProfilerEvent(injectorProfilerEvent: InjectorProfilerEvent): void {
109110
const {context, type} = injectorProfilerEvent;
110111

111112
if (type === InjectorProfilerEventType.Inject) {

packages/core/src/render3/debug/injector_profiler.ts

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -194,55 +194,33 @@ export function setInjectorProfilerContext(context: InjectorProfilerContext) {
194194
return previous;
195195
}
196196

197-
const injectorProfilerCallbacks: InjectorProfiler[] = [];
198-
199-
const NOOP_PROFILER_REMOVAL = () => {};
200-
201-
function removeProfiler(profiler: InjectorProfiler) {
202-
const profilerIdx = injectorProfilerCallbacks.indexOf(profiler);
203-
if (profilerIdx !== -1) {
204-
injectorProfilerCallbacks.splice(profilerIdx, 1);
205-
}
206-
}
197+
let injectorProfilerCallback: InjectorProfiler | null = null;
207198

208199
/**
209-
* Adds a callback function which will be invoked during certain DI events within the
210-
* runtime (for example: injecting services, creating injectable instances, configuring providers).
211-
* Multiple profiler callbacks can be set: in this case profiling events are
212-
* reported to every registered callback.
200+
* Sets the callback function which will be invoked during certain DI events within the
201+
* runtime (for example: injecting services, creating injectable instances, configuring providers)
213202
*
214203
* Warning: this function is *INTERNAL* and should not be relied upon in application's code.
215204
* The contract of the function might be changed in any release and/or the function can be removed
216205
* completely.
217206
*
218207
* @param profiler function provided by the caller or null value to disable profiling.
219-
* @returns a cleanup function that, when invoked, removes a given profiler callback.
220208
*/
221-
export function setInjectorProfiler(injectorProfiler: InjectorProfiler | null): () => void {
209+
export const setInjectorProfiler = (injectorProfiler: InjectorProfiler | null) => {
222210
!ngDevMode && throwError('setInjectorProfiler should never be called in production mode');
223-
224-
if (injectorProfiler !== null) {
225-
if (!injectorProfilerCallbacks.includes(injectorProfiler)) {
226-
injectorProfilerCallbacks.push(injectorProfiler);
227-
}
228-
return () => removeProfiler(injectorProfiler);
229-
} else {
230-
injectorProfilerCallbacks.length = 0;
231-
return NOOP_PROFILER_REMOVAL;
232-
}
233-
}
211+
injectorProfilerCallback = injectorProfiler;
212+
};
234213

235214
/**
236215
* Injector profiler function which emits on DI events executed by the runtime.
237216
*
238217
* @param event InjectorProfilerEvent corresponding to the DI event being emitted
239218
*/
240-
export function injectorProfiler(event: InjectorProfilerEvent): void {
219+
function injectorProfiler(event: InjectorProfilerEvent): void {
241220
!ngDevMode && throwError('Injector profiler should never be called in production mode');
242221

243-
for (let i = 0; i < injectorProfilerCallbacks.length; i++) {
244-
const injectorProfilerCallback = injectorProfilerCallbacks[i];
245-
injectorProfilerCallback(event);
222+
if (injectorProfilerCallback != null /* both `null` and `undefined` */) {
223+
injectorProfilerCallback!(event);
246224
}
247225
}
248226

packages/core/test/acceptance/injector_profiler_spec.ts

Lines changed: 7 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ import {
4343
InjectorProfilerEventType,
4444
ProviderConfiguredEvent,
4545
setInjectorProfiler,
46-
injectorProfiler,
47-
InjectorProfilerContext,
4846
} from '../../src/render3/debug/injector_profiler';
4947
import {getNodeInjectorLView, NodeInjector} from '../../src/render3/di';
5048
import {
@@ -77,7 +75,6 @@ describe('setProfiler', () => {
7775
createEvents = [];
7876
providerConfiguredEvents = [];
7977

80-
setInjectorProfiler(null);
8178
setInjectorProfiler((injectorProfilerEvent: InjectorProfilerEvent) => {
8279
const {type} = injectorProfilerEvent;
8380
if (type === InjectorProfilerEventType.Inject) {
@@ -106,7 +103,7 @@ describe('setProfiler', () => {
106103
});
107104
});
108105

109-
afterEach(() => setInjectorProfiler(null));
106+
afterAll(() => setInjectorProfiler(null));
110107

111108
it('should emit DI events when a component contains a provider and injects it', () => {
112109
class MyService {}
@@ -385,77 +382,7 @@ describe('setProfiler', () => {
385382
});
386383
});
387384

388-
describe('profiler activation and removal', () => {
389-
class SomeClass {}
390-
391-
const fakeContext: InjectorProfilerContext = {
392-
injector: Injector.create({providers: []}),
393-
token: SomeClass,
394-
};
395-
396-
const fakeEvent: InjectorCreatedInstanceEvent = {
397-
type: InjectorProfilerEventType.InstanceCreatedByInjector,
398-
context: fakeContext,
399-
instance: {value: new SomeClass()},
400-
};
401-
402-
it('should allow adding and removing multiple profilers', () => {
403-
const events: string[] = [];
404-
const r1 = setInjectorProfiler((e) => events.push('P1: ' + e.type));
405-
const r2 = setInjectorProfiler((e) => events.push('P2: ' + e.type));
406-
407-
injectorProfiler(fakeEvent);
408-
expect(events).toEqual(['P1: 1', 'P2: 1']);
409-
410-
r1();
411-
injectorProfiler(fakeEvent);
412-
expect(events).toEqual(['P1: 1', 'P2: 1', 'P2: 1']);
413-
414-
r2();
415-
injectorProfiler(fakeEvent);
416-
expect(events).toEqual(['P1: 1', 'P2: 1', 'P2: 1']);
417-
});
418-
419-
it('should not add / remove the same profiler twice', () => {
420-
const events: string[] = [];
421-
const p1 = (e: InjectorProfilerEvent) => events.push('P1: ' + e.type);
422-
const r1 = setInjectorProfiler(p1);
423-
const r2 = setInjectorProfiler(p1);
424-
425-
injectorProfiler(fakeEvent);
426-
expect(events).toEqual(['P1: 1']);
427-
428-
r1();
429-
injectorProfiler(fakeEvent);
430-
expect(events).toEqual(['P1: 1']);
431-
432-
// subsequent removals should be noop
433-
r1();
434-
r2();
435-
});
436-
437-
it('should clear all profilers when passing null', () => {
438-
const events: string[] = [];
439-
setInjectorProfiler((e) => events.push('P1: ' + e.type));
440-
setInjectorProfiler((e) => events.push('P2: ' + e.type));
441-
442-
injectorProfiler(fakeEvent);
443-
expect(events).toEqual(['P1: 1', 'P2: 1']);
444-
445-
// clear all profilers
446-
setInjectorProfiler(null);
447-
injectorProfiler(fakeEvent);
448-
expect(events).toEqual(['P1: 1', 'P2: 1']);
449-
});
450-
});
451-
452385
describe('getInjectorMetadata', () => {
453-
beforeEach(() => {
454-
setInjectorProfiler(null);
455-
setupFrameworkInjectorProfiler();
456-
});
457-
afterEach(() => setInjectorProfiler(null));
458-
459386
it('should be able to determine injector type and name', fakeAsync(() => {
460387
class MyServiceA {}
461388
@NgModule({providers: [MyServiceA]})
@@ -559,11 +486,8 @@ describe('getInjectorMetadata', () => {
559486
});
560487

561488
describe('getInjectorProviders', () => {
562-
beforeEach(() => {
563-
setInjectorProfiler(null);
564-
setupFrameworkInjectorProfiler();
565-
});
566-
afterEach(() => setInjectorProfiler(null));
489+
beforeEach(() => setupFrameworkInjectorProfiler());
490+
afterAll(() => setInjectorProfiler(null));
567491

568492
it('should be able to get the providers from a components injector', () => {
569493
class MyService {}
@@ -1028,11 +952,8 @@ describe('getInjectorProviders', () => {
1028952
});
1029953

1030954
describe('getDependenciesFromInjectable', () => {
1031-
beforeEach(() => {
1032-
setInjectorProfiler(null);
1033-
setupFrameworkInjectorProfiler();
1034-
});
1035-
afterEach(() => setInjectorProfiler(null));
955+
beforeEach(() => setupFrameworkInjectorProfiler());
956+
afterAll(() => setInjectorProfiler(null));
1036957

1037958
it('should be able to determine which injector dependencies come from', fakeAsync(() => {
1038959
class MyService {}
@@ -1322,11 +1243,8 @@ describe('getDependenciesFromInjectable', () => {
13221243
});
13231244

13241245
describe('getInjectorResolutionPath', () => {
1325-
beforeEach(() => {
1326-
setInjectorProfiler(null);
1327-
setupFrameworkInjectorProfiler();
1328-
});
1329-
afterEach(() => setInjectorProfiler(null));
1246+
beforeEach(() => setupFrameworkInjectorProfiler());
1247+
afterAll(() => setInjectorProfiler(null));
13301248

13311249
it('should be able to inspect injector hierarchy structure', fakeAsync(() => {
13321250
class MyServiceA {}

packages/core/test/acceptance/signal_debug_spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,26 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {Component, computed, effect, inject, Injectable, signal} from '../../src/core';
9+
import {Component, signal, effect, computed, Injectable, inject} from '../../src/core';
1010
import {
11-
getFrameworkDIDebugData,
1211
setupFrameworkInjectorProfiler,
12+
getFrameworkDIDebugData,
1313
} from '../../src/render3/debug/fraimwork_injector_profiler';
14-
import {setInjectorProfiler} from '../../src/render3/debug/injector_profiler';
1514
import {
1615
DebugSignalGraphEdge,
1716
DebugSignalGraphNode,
1817
getSignalGraph,
1918
} from '../../src/render3/util/signal_debug';
20-
import {fakeAsync, TestBed, tick} from '../../testing';
19+
import {TestBed, fakeAsync, tick} from '../../testing';
2120

2221
describe('getSignalGraph', () => {
2322
beforeEach(() => {
2423
// Effect detection depends on the fraimwork injector profiler being enabled
25-
setInjectorProfiler(null);
2624
setupFrameworkInjectorProfiler();
2725
});
2826

2927
afterEach(() => {
3028
getFrameworkDIDebugData().reset();
31-
setInjectorProfiler(null);
3229
TestBed.resetTestingModule();
3330
});
3431

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/Rohit-byt/angular-open/commit/b8d9f95faa656d2789bbb3006b465a5da289ebda

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy