Skip to content

Commit b447b96

Browse files
authored
fix: introduce Angular v20 compatibility by removing "InjectFlags" usage (#1532)
1 parent e308c52 commit b447b96

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

libs/cdk/date/date-suggestion/date-suggestion.composer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Inject, Injectable, InjectFlags, Injector} from '@angular/core';
1+
import {Inject, Injectable, Injector} from '@angular/core';
22
import {Nullable} from '@angular-ru/cdk/typings';
33
import {isNil} from '@angular-ru/cdk/utils';
44

@@ -28,7 +28,7 @@ export class DateSuggestionComposer<StrategyKeys extends StrategyKey = StrategyK
2828
...(descriptor.providers ?? []),
2929
],
3030
parent: this.injector,
31-
}).get(descriptor.strategy, null, InjectFlags.Optional);
31+
}).get(descriptor.strategy, null, {optional: true});
3232

3333
if (isNil(strategy)) {
3434
throw new Error('This type of date suggestion is not supported');
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable no-redeclare */
2-
import {AbstractType, InjectionToken, Type} from '@angular/core';
2+
import {AbstractType, InjectionToken, InjectOptions, Type} from '@angular/core';
33
import {
4-
InjectFlags,
54
ɵɵdirectiveInject as ivyDirectiveInject,
65
ɵɵinject as ivyInject,
76
} from '@angular/core';
@@ -10,16 +9,16 @@ import {Fn, Nullable} from '@angular-ru/cdk/typings';
109
function wrapperForInject<T>(
1110
wrap: Fn,
1211
token: AbstractType<T> | InjectionToken<T> | Type<T>,
13-
flags?: InjectFlags,
12+
options?: InjectOptions,
1413
): Nullable<T> {
15-
if (InjectFlags.Optional) {
14+
if (options?.optional) {
1615
try {
17-
return wrap(token, flags!);
16+
return wrap(token, options);
1817
} catch {
1918
return null;
2019
}
2120
} else {
22-
return flags ? wrap(token, flags) : wrap(token);
21+
return options ? wrap(token, options) : wrap(token);
2322
}
2423
}
2524

@@ -31,14 +30,14 @@ export function directiveInject<T>(
3130
): T;
3231
export function directiveInject<T>(
3332
token: AbstractType<T> | InjectionToken<T> | Type<T>,
34-
flags: InjectFlags,
33+
options: InjectOptions,
3534
): Nullable<T>;
3635

3736
export function directiveInject<T>(
3837
token: AbstractType<T> | InjectionToken<T> | Type<T>,
39-
flags?: InjectFlags,
38+
options?: InjectOptions,
4039
): Nullable<T> {
41-
return wrapperForInject(ivyDirectiveInject, token, flags);
40+
return wrapperForInject(ivyDirectiveInject, token, options);
4241
}
4342

4443
/**
@@ -47,12 +46,12 @@ export function directiveInject<T>(
4746
export function inject<T>(token: AbstractType<T> | InjectionToken<T> | Type<T>): T;
4847
export function inject<T>(
4948
token: AbstractType<T> | InjectionToken<T> | Type<T>,
50-
flags: InjectFlags,
49+
options: InjectOptions,
5150
): Nullable<T>;
5251

5352
export function inject<T>(
5453
token: AbstractType<T> | InjectionToken<T> | Type<T>,
55-
flags?: InjectFlags,
54+
options?: InjectOptions,
5655
): Nullable<T> {
57-
return wrapperForInject(ivyInject, token, flags);
56+
return wrapperForInject(ivyInject, token, options);
5857
}

libs/cdk/tests/ivy/injection-utils.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, Injectable, InjectFlags} from '@angular/core';
1+
import {Component, Injectable} from '@angular/core';
22
import {TestBed} from '@angular/core/testing';
33
import {directiveInject, inject} from '@angular-ru/cdk/ivy';
44
import {Nullable} from '@angular-ru/cdk/typings';
@@ -68,7 +68,7 @@ describe('[TEST]: injection utils', () => {
6868
public b: Nullable<B> = null;
6969

7070
constructor() {
71-
this.b = inject(B, InjectFlags.Optional);
71+
this.b = inject(B, {optional: true});
7272
}
7373
}
7474

@@ -92,7 +92,7 @@ describe('[TEST]: injection utils', () => {
9292
public service: Nullable<Service>;
9393

9494
constructor() {
95-
this.service = directiveInject(Service, InjectFlags.Optional);
95+
this.service = directiveInject(Service, {optional: true});
9696
}
9797
}
9898

libs/ngxs/decorators/data-action/data-action.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {InjectFlags} from '@angular/core';
21
import {$args} from '@angular-ru/cdk/function';
32
import {Descriptor, PlainObjectOf} from '@angular-ru/cdk/typings';
43
import {isNil, isNotNil, isTrue} from '@angular-ru/cdk/utils';
@@ -127,11 +126,8 @@ export function DataAction(options: RepositoryActionOptions = {}): MethodDecorat
127126
}
128127

129128
function mergeConfig(options: RepositoryActionOptions): RepositoryActionOptions {
130-
const globalConfig: NgxsDataConfig | undefined = NgxsDataInjector?.injector?.get(
131-
NGXS_DATA_CONFIG,
132-
undefined,
133-
InjectFlags.Optional,
134-
);
129+
const globalConfig: NgxsDataConfig | null | undefined =
130+
NgxsDataInjector?.injector?.get(NGXS_DATA_CONFIG, undefined, {optional: true});
135131
const mergedOptions: RepositoryActionOptions = {...REPOSITORY_ACTION_OPTIONS};
136132

137133
if (

0 commit comments

Comments
 (0)