Skip to content

Commit 3c84525

Browse files
authored
refactor(multiple): remove unnecessary dependency arrays (#31903)
We don't really need to use the `deps` arrays anymore since we've fully switched over to `inject`. These changes remove the leftovers.
1 parent 84fc0d9 commit 3c84525

File tree

9 files changed

+12
-45
lines changed

9 files changed

+12
-45
lines changed

goldens/cdk/menu/index.api.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { Observable } from 'rxjs';
2121
import { OnChanges } from '@angular/core';
2222
import { OnDestroy } from '@angular/core';
2323
import { OnInit } from '@angular/core';
24-
import { Optional } from '@angular/core';
2524
import { QueryList } from '@angular/core';
2625
import { Renderer2 } from '@angular/core';
2726
import * as rxjs from 'rxjs';
@@ -368,15 +367,13 @@ export { MenuTracker }
368367
// @public
369368
export const PARENT_OR_NEW_INLINE_MENU_STACK_PROVIDER: (orientation: "vertical" | "horizontal") => {
370369
provide: InjectionToken<MenuStack>;
371-
deps: Optional[][];
372-
useFactory: (parentMenuStack?: MenuStack) => MenuStack;
370+
useFactory: () => MenuStack;
373371
};
374372

375373
// @public
376374
export const PARENT_OR_NEW_MENU_STACK_PROVIDER: {
377375
provide: InjectionToken<MenuStack>;
378-
deps: Optional[][];
379-
useFactory: (parentMenuStack?: MenuStack) => MenuStack;
376+
useFactory: () => MenuStack;
380377
};
381378

382379
// @public

src/cdk/menu/menu-stack.ts

Lines changed: 4 additions & 5 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, Inject, Injectable, InjectionToken, Optional, SkipSelf} from '@angular/core';
9+
import {inject, Injectable, InjectionToken} from '@angular/core';
1010
import {_IdGenerator} from '../a11y';
1111
import {Observable, Subject} from 'rxjs';
1212
import {debounceTime, distinctUntilChanged, startWith} from 'rxjs/operators';
@@ -30,17 +30,16 @@ export const MENU_STACK = new InjectionToken<MenuStack>('cdk-menu-stack');
3030
/** Provider that provides the parent menu stack, or a new menu stack if there is no parent one. */
3131
export const PARENT_OR_NEW_MENU_STACK_PROVIDER = {
3232
provide: MENU_STACK,
33-
deps: [[new Optional(), new SkipSelf(), new Inject(MENU_STACK)]],
34-
useFactory: (parentMenuStack?: MenuStack) => parentMenuStack || new MenuStack(),
33+
useFactory: () => inject(MENU_STACK, {optional: true, skipSelf: true}) || new MenuStack(),
3534
};
3635

3736
/** Provider that provides the parent menu stack, or a new inline menu stack if there is no parent one. */
3837
export const PARENT_OR_NEW_INLINE_MENU_STACK_PROVIDER = (
3938
orientation: 'vertical' | 'horizontal',
4039
) => ({
4140
provide: MENU_STACK,
42-
deps: [[new Optional(), new SkipSelf(), new Inject(MENU_STACK)]],
43-
useFactory: (parentMenuStack?: MenuStack) => parentMenuStack || MenuStack.inline(orientation),
41+
useFactory: () =>
42+
inject(MENU_STACK, {optional: true, skipSelf: true}) || MenuStack.inline(orientation),
4443
});
4544

4645
/** Options that can be provided to the close or closeAll methods. */

src/cdk/observers/observe-content.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ describe('Observe content directive', () => {
4646
// test this scenario reliably without risking flaky tests, which is why we supply a mock
4747
// MutationObserver and check that the methods are called at the right time.
4848
TestBed.overrideProvider(MutationObserverFactory, {
49-
deps: [],
5049
useFactory: () => ({
5150
create: () => ({observe: observeSpy, disconnect: disconnectSpy}),
5251
}),

src/cdk/scrolling/virtual-scroll-viewport.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ import {
1919
effect,
2020
ElementRef,
2121
inject,
22-
Inject,
2322
Injector,
2423
Input,
2524
OnDestroy,
2625
OnInit,
27-
Optional,
2826
Output,
2927
signal,
3028
untracked,
@@ -74,11 +72,8 @@ const SCROLL_SCHEDULER =
7472
providers: [
7573
{
7674
provide: CdkScrollable,
77-
useFactory: (
78-
virtualScrollable: CdkVirtualScrollable | null,
79-
viewport: CdkVirtualScrollViewport,
80-
) => virtualScrollable || viewport,
81-
deps: [[new Optional(), new Inject(VIRTUAL_SCROLLABLE)], CdkVirtualScrollViewport],
75+
useFactory: () =>
76+
inject(VIRTUAL_SCROLLABLE, {optional: true}) || inject(CdkVirtualScrollViewport),
8277
},
8378
],
8479
})

src/cdk/testing/private/fake-directionality.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ export function provideFakeDirectionality(direction: Direction | WritableSignal<
3333
provide: Directionality,
3434
useFactory: () =>
3535
new FakeDirectionality(typeof direction === 'string' ? signal(direction) : direction),
36-
deps: [],
3736
};
3837
}

src/material-date-fns-adapter/adapter/index.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77
*/
88

99
import {NgModule, Provider} from '@angular/core';
10-
import {
11-
DateAdapter,
12-
MAT_DATE_FORMATS,
13-
MAT_DATE_LOCALE,
14-
MatDateFormats,
15-
} from '@angular/material/core';
10+
import {DateAdapter, MAT_DATE_FORMATS, MatDateFormats} from '@angular/material/core';
1611
import {DateFnsAdapter} from './date-fns-adapter';
1712
import {MAT_DATE_FNS_FORMATS} from './date-fns-formats';
1813

@@ -24,7 +19,6 @@ export * from './date-fns-formats';
2419
{
2520
provide: DateAdapter,
2621
useClass: DateFnsAdapter,
27-
deps: [MAT_DATE_LOCALE],
2822
},
2923
],
3024
})
@@ -40,7 +34,6 @@ export function provideDateFnsAdapter(formats: MatDateFormats = MAT_DATE_FNS_FOR
4034
{
4135
provide: DateAdapter,
4236
useClass: DateFnsAdapter,
43-
deps: [MAT_DATE_LOCALE],
4437
},
4538
{provide: MAT_DATE_FORMATS, useValue: formats},
4639
];

src/material-luxon-adapter/adapter/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@
77
*/
88

99
import {NgModule, Provider} from '@angular/core';
10-
import {
11-
DateAdapter,
12-
MAT_DATE_FORMATS,
13-
MAT_DATE_LOCALE,
14-
MatDateFormats,
15-
} from '@angular/material/core';
16-
import {MAT_LUXON_DATE_ADAPTER_OPTIONS, LuxonDateAdapter} from './luxon-date-adapter';
10+
import {DateAdapter, MAT_DATE_FORMATS, MatDateFormats} from '@angular/material/core';
11+
import {LuxonDateAdapter} from './luxon-date-adapter';
1712
import {MAT_LUXON_DATE_FORMATS} from './luxon-date-formats';
1813

1914
export * from './luxon-date-adapter';
@@ -24,7 +19,6 @@ export * from './luxon-date-formats';
2419
{
2520
provide: DateAdapter,
2621
useClass: LuxonDateAdapter,
27-
deps: [MAT_DATE_LOCALE, MAT_LUXON_DATE_ADAPTER_OPTIONS],
2822
},
2923
],
3024
})
@@ -42,7 +36,6 @@ export function provideLuxonDateAdapter(
4236
{
4337
provide: DateAdapter,
4438
useClass: LuxonDateAdapter,
45-
deps: [MAT_DATE_LOCALE, MAT_LUXON_DATE_ADAPTER_OPTIONS],
4639
},
4740
{provide: MAT_DATE_FORMATS, useValue: formats},
4841
];

src/material-moment-adapter/adapter/index.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77
*/
88

99
import {NgModule, Provider} from '@angular/core';
10-
import {
11-
DateAdapter,
12-
MAT_DATE_FORMATS,
13-
MAT_DATE_LOCALE,
14-
MatDateFormats,
15-
} from '@angular/material/core';
10+
import {DateAdapter, MAT_DATE_FORMATS, MatDateFormats} from '@angular/material/core';
1611
import {
1712
MAT_MOMENT_DATE_ADAPTER_OPTIONS,
1813
MatMomentDateAdapterOptions,
@@ -28,7 +23,6 @@ export * from './moment-date-formats';
2823
{
2924
provide: DateAdapter,
3025
useClass: MomentDateAdapter,
31-
deps: [MAT_DATE_LOCALE, MAT_MOMENT_DATE_ADAPTER_OPTIONS],
3226
},
3327
],
3428
})
@@ -47,7 +41,6 @@ export function provideMomentDateAdapter(
4741
{
4842
provide: DateAdapter,
4943
useClass: MomentDateAdapter,
50-
deps: [MAT_DATE_LOCALE, MAT_MOMENT_DATE_ADAPTER_OPTIONS],
5144
},
5245
{provide: MAT_DATE_FORMATS, useValue: formats},
5346
];

src/material/snack-bar/snack-bar.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,6 @@ describe('MatSnackBar', () => {
509509
viewContainerFixture.destroy();
510510

511511
TestBed.resetTestingModule().overrideProvider(MAT_SNACK_BAR_DEFAULT_OPTIONS, {
512-
deps: [],
513512
useFactory: () => ({panelClass: 'custom-class'}),
514513
});
515514

0 commit comments

Comments
 (0)