Skip to content

Commit 8f59295

Browse files
crisbetothePunderWoman
authored andcommitted
refactor(core): remove unnecessary deps arrays (#63823)
We don't need to use the `deps` array syntax anymore since we have the `inject` function. These changes clean up the relevant usages. PR Close #63823
1 parent 7fd3db0 commit 8f59295

15 files changed

Lines changed: 74 additions & 89 deletions

File tree

devtools/projects/shell-browser/src/app/app.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {ChromeApplicationEnvironment} from './chrome-application-environment';
1313
import {ChromeApplicationOperations} from './chrome-application-operations';
1414
import {Events, MessageBus, PriorityAwareMessageBus} from '../../../protocol';
1515
import {FrameManager} from '../../../ng-devtools/src/lib/application-services/frame_manager';
16-
import {Platform} from '@angular/cdk/platform';
1716
import {ChromeMessageBus} from './chrome-message-bus';
1817

1918
export const appConfig: ApplicationConfig = {
@@ -23,7 +22,6 @@ export const appConfig: ApplicationConfig = {
2322
{
2423
provide: ApplicationOperations,
2524
useClass: ChromeApplicationOperations,
26-
deps: [Platform],
2725
},
2826
{
2927
provide: ApplicationEnvironment,

goldens/public-api/router/upgrade/index.api.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
```ts
66

77
import { ComponentRef } from '@angular/core';
8-
import { InjectionToken } from '@angular/core';
8+
import * as i0 from '@angular/core';
99
import { UpgradeModule } from '@angular/upgrade/static';
1010

1111
// @public
1212
export const RouterUpgradeInitializer: {
13-
provide: InjectionToken<readonly ((compRef: ComponentRef<any>) => void)[]>;
13+
provide: i0.InjectionToken<readonly ((compRef: ComponentRef<any>) => void)[]>;
1414
multi: boolean;
15-
useFactory: (ngUpgrade: UpgradeModule) => () => void;
16-
deps: (typeof UpgradeModule)[];
15+
useFactory: () => () => void;
1716
};
1817

1918
// @public

packages/common/src/i18n/localization.ts

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

9-
import {Inject, Injectable, LOCALE_ID, ɵRuntimeError as RuntimeError} from '@angular/core';
9+
import {inject, Inject, Injectable, LOCALE_ID, ɵRuntimeError as RuntimeError} from '@angular/core';
1010

1111
import {getLocalePluralCase, Plural} from './locale_data_api';
1212
import {RuntimeErrorCode} from '../errors';
@@ -16,8 +16,7 @@ import {RuntimeErrorCode} from '../errors';
1616
*/
1717
@Injectable({
1818
providedIn: 'root',
19-
useFactory: (locale: string) => new NgLocaleLocalization(locale),
20-
deps: [LOCALE_ID],
19+
useFactory: () => new NgLocaleLocalization(inject(LOCALE_ID)),
2120
})
2221
export abstract class NgLocalization {
2322
abstract getPluralCategory(value: any, locale?: string): string;

packages/common/upgrade/src/location_upgrade_module.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
PathLocationStrategy,
1616
PlatformLocation,
1717
} from '../../index';
18-
import {Inject, InjectionToken, ModuleWithProviders, NgModule, Optional} from '@angular/core';
18+
import {inject, InjectionToken, ModuleWithProviders, NgModule} from '@angular/core';
1919
import {UpgradeModule} from '@angular/upgrade/static';
2020

2121
import {$locationShim, $locationShimProvider} from './location_shim';
@@ -80,26 +80,26 @@ export class LocationUpgradeModule {
8080
{
8181
provide: $locationShim,
8282
useFactory: provide$location,
83-
deps: [UpgradeModule, Location, PlatformLocation, UrlCodec, LocationStrategy],
8483
},
8584
{provide: LOCATION_UPGRADE_CONFIGURATION, useValue: config ? config : {}},
86-
{provide: UrlCodec, useFactory: provideUrlCodec, deps: [LOCATION_UPGRADE_CONFIGURATION]},
85+
{provide: UrlCodec, useFactory: provideUrlCodec},
8786
{
8887
provide: APP_BASE_HREF_RESOLVED,
8988
useFactory: provideAppBaseHref,
90-
deps: [LOCATION_UPGRADE_CONFIGURATION, [new Inject(APP_BASE_HREF), new Optional()]],
9189
},
9290
{
9391
provide: LocationStrategy,
9492
useFactory: provideLocationStrategy,
95-
deps: [PlatformLocation, APP_BASE_HREF_RESOLVED, LOCATION_UPGRADE_CONFIGURATION],
9693
},
9794
],
9895
};
9996
}
10097
}
10198

102-
export function provideAppBaseHref(config: LocationUpgradeConfig, appBaseHref?: string) {
99+
function provideAppBaseHref() {
100+
const config = inject(LOCATION_UPGRADE_CONFIGURATION);
101+
const appBaseHref = inject(APP_BASE_HREF, {optional: true});
102+
103103
if (config && config.appBaseHref != null) {
104104
return config.appBaseHref;
105105
} else if (appBaseHref != null) {
@@ -108,34 +108,28 @@ export function provideAppBaseHref(config: LocationUpgradeConfig, appBaseHref?:
108108
return '';
109109
}
110110

111-
export function provideUrlCodec(config: LocationUpgradeConfig) {
111+
function provideUrlCodec() {
112+
const config = inject(LOCATION_UPGRADE_CONFIGURATION);
112113
const codec = (config && config.urlCodec) || AngularJSUrlCodec;
113114
return new (codec as any)();
114115
}
115116

116-
export function provideLocationStrategy(
117-
platformLocation: PlatformLocation,
118-
baseHref: string,
119-
options: LocationUpgradeConfig = {},
120-
) {
117+
function provideLocationStrategy() {
118+
const platformLocation = inject(PlatformLocation);
119+
const baseHref = inject(APP_BASE_HREF_RESOLVED);
120+
const options = inject(LOCATION_UPGRADE_CONFIGURATION);
121121
return options.useHash
122122
? new HashLocationStrategy(platformLocation, baseHref)
123123
: new PathLocationStrategy(platformLocation, baseHref);
124124
}
125125

126-
export function provide$location(
127-
ngUpgrade: UpgradeModule,
128-
location: Location,
129-
platformLocation: PlatformLocation,
130-
urlCodec: UrlCodec,
131-
locationStrategy: LocationStrategy,
132-
) {
126+
function provide$location() {
133127
const $locationProvider = new $locationShimProvider(
134-
ngUpgrade,
135-
location,
136-
platformLocation,
137-
urlCodec,
138-
locationStrategy,
128+
inject(UpgradeModule),
129+
inject(Location),
130+
inject(PlatformLocation),
131+
inject(UrlCodec),
132+
inject(LocationStrategy),
139133
);
140134

141135
return $locationProvider.$get();

packages/misc/angular-in-memory-web-api/src/http-client-in-memory-web-api-module.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88

99
import {XhrFactory} from '@angular/common';
1010
import {HttpBackend} from '@angular/common/http';
11-
import {ModuleWithProviders, NgModule, Type} from '@angular/core';
11+
import {inject, ModuleWithProviders, NgModule, Type} from '@angular/core';
1212

1313
import {HttpClientBackendService} from './http-client-backend-service';
1414
import {InMemoryBackendConfig, InMemoryBackendConfigArgs, InMemoryDbService} from './interfaces';
1515

1616
// Internal - Creates the in-mem backend for the HttpClient module
1717
// AoT requires factory to be exported
18-
export function httpClientInMemBackendServiceFactory(
19-
dbService: InMemoryDbService,
20-
options: InMemoryBackendConfig,
21-
xhrFactory: XhrFactory,
22-
): HttpBackend {
23-
return new HttpClientBackendService(dbService, options, xhrFactory) as HttpBackend;
18+
export function httpClientInMemBackendServiceFactory(): HttpBackend {
19+
return new HttpClientBackendService(
20+
inject(InMemoryDbService),
21+
inject(InMemoryBackendConfig),
22+
inject(XhrFactory),
23+
) as HttpBackend;
2424
}
2525

2626
@NgModule()
@@ -55,7 +55,6 @@ export class HttpClientInMemoryWebApiModule {
5555
{
5656
provide: HttpBackend,
5757
useFactory: httpClientInMemBackendServiceFactory,
58-
deps: [InMemoryDbService, InMemoryBackendConfig, XhrFactory],
5958
},
6059
],
6160
};

packages/misc/angular-in-memory-web-api/src/in-memory-web-api-module.ts

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

9-
import {XhrFactory} from '@angular/common';
109
import {HttpBackend} from '@angular/common/http';
1110
import {ModuleWithProviders, NgModule, Type} from '@angular/core';
1211

@@ -45,7 +44,6 @@ export class InMemoryWebApiModule {
4544
{
4645
provide: HttpBackend,
4746
useFactory: httpClientInMemBackendServiceFactory,
48-
deps: [InMemoryDbService, InMemoryBackendConfig, XhrFactory],
4947
},
5048
],
5149
};

packages/platform-browser/animations/async/src/providers.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
NgZone,
1515
RendererFactory2,
1616
ɵperformanceMarkFeature as performanceMarkFeature,
17+
inject,
1718
} from '@angular/core';
1819
import {ɵDomRendererFactory2 as DomRendererFactory2} from '../../../index';
1920

@@ -61,10 +62,14 @@ export function provideAnimationsAsync(
6162
return makeEnvironmentProviders([
6263
{
6364
provide: RendererFactory2,
64-
useFactory: (doc: Document, renderer: DomRendererFactory2, zone: NgZone) => {
65-
return new AsyncAnimationRendererFactory(doc, renderer, zone, type);
65+
useFactory: () => {
66+
return new AsyncAnimationRendererFactory(
67+
inject(DOCUMENT),
68+
inject(DomRendererFactory2),
69+
inject(NgZone),
70+
type,
71+
);
6672
},
67-
deps: [DOCUMENT, DomRendererFactory2, NgZone],
6873
},
6974
{
7075
provide: ANIMATION_MODULE_TYPE,

packages/platform-browser/animations/src/providers.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
OnDestroy,
2626
Provider,
2727
RendererFactory2,
28-
ɵChangeDetectionScheduler as ChangeDetectionScheduler,
2928
} from '@angular/core';
3029
import {ɵDomRendererFactory2 as DomRendererFactory2} from '../../index';
3130

@@ -51,12 +50,12 @@ export function instantiateDefaultStyleNormalizer() {
5150
return new WebAnimationsStyleNormalizer();
5251
}
5352

54-
export function instantiateRendererFactory(
55-
renderer: DomRendererFactory2,
56-
engine: AnimationEngine,
57-
zone: NgZone,
58-
) {
59-
return new AnimationRendererFactory(renderer, engine, zone);
53+
export function instantiateRendererFactory() {
54+
return new AnimationRendererFactory(
55+
inject(DomRendererFactory2),
56+
inject(AnimationEngine),
57+
inject(NgZone),
58+
);
6059
}
6160

6261
const SHARED_ANIMATION_PROVIDERS: Provider[] = [
@@ -65,7 +64,6 @@ const SHARED_ANIMATION_PROVIDERS: Provider[] = [
6564
{
6665
provide: RendererFactory2,
6766
useFactory: instantiateRendererFactory,
68-
deps: [DomRendererFactory2, AnimationEngine, NgZone],
6967
},
7068
];
7169

packages/platform-browser/src/browser.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
ErrorHandler,
2121
InjectionToken,
2222
NgModule,
23-
NgZone,
2423
PLATFORM_ID,
2524
PLATFORM_INITIALIZER,
2625
platformCore,
@@ -29,7 +28,6 @@ import {
2928
RendererFactory2,
3029
StaticProvider,
3130
Testability,
32-
TestabilityRegistry,
3331
Type,
3432
ɵINJECTOR_SCOPE as INJECTOR_SCOPE,
3533
ɵinternalCreateApplication as internalCreateApplication,
@@ -239,12 +237,10 @@ const TESTABILITY_PROVIDERS = [
239237
{
240238
provide: TESTABILITY,
241239
useClass: Testability,
242-
deps: [NgZone, TestabilityRegistry, TESTABILITY_GETTER],
243240
},
244241
{
245242
provide: Testability, // Also provide as `Testability` for backwards-compatibility.
246243
useClass: Testability,
247-
deps: [NgZone, TestabilityRegistry, TESTABILITY_GETTER],
248244
},
249245
];
250246

@@ -255,9 +251,8 @@ const BROWSER_MODULE_PROVIDERS: Provider[] = [
255251
provide: EVENT_MANAGER_PLUGINS,
256252
useClass: DomEventsPlugin,
257253
multi: true,
258-
deps: [DOCUMENT],
259254
},
260-
{provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, multi: true, deps: [DOCUMENT]},
255+
{provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, multi: true},
261256
DomRendererFactory2,
262257
SharedStylesHost,
263258
EventManager,

packages/platform-server/src/location.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
PlatformLocation,
1414
ɵgetDOM as getDOM,
1515
} from '@angular/common';
16-
import {Inject, Injectable, Optional, ɵWritable as Writable} from '@angular/core';
16+
import {inject, Inject, Injectable, Optional, ɵWritable as Writable} from '@angular/core';
1717
import {Subject} from 'rxjs';
1818

1919
import {INITIAL_CONFIG, PlatformConfig} from './tokens';
@@ -57,12 +57,10 @@ export class ServerPlatformLocation implements PlatformLocation {
5757
public readonly search: string = '';
5858
public readonly hash: string = '';
5959
private _hashUpdate = new Subject<LocationChangeEvent>();
60+
private _doc = inject(DOCUMENT);
6061

61-
constructor(
62-
@Inject(DOCUMENT) private _doc: any,
63-
@Optional() @Inject(INITIAL_CONFIG) _config: any,
64-
) {
65-
const config = _config as PlatformConfig | null;
62+
constructor() {
63+
const config = inject(INITIAL_CONFIG, {optional: true});
6664
if (!config) {
6765
return;
6866
}
@@ -74,7 +72,7 @@ export class ServerPlatformLocation implements PlatformLocation {
7472
this.pathname = url.pathname;
7573
this.search = url.search;
7674
this.hash = url.hash;
77-
this.href = _doc.location.href;
75+
this.href = this._doc.location.href;
7876
}
7977
}
8078

0 commit comments

Comments
 (0)