Skip to content

Commit bc253ae

Browse files
authored
fix(schematics): use inject in generated data, effect, and component-store templates (#5142)
Closes #5136
1 parent 197abbf commit bc253ae

5 files changed

Lines changed: 24 additions & 24 deletions

File tree

modules/schematics/src/data/__snapshots__/index.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ exports[`Data Schematic should create a model interface 1`] = `
88
`;
99

1010
exports[`Data Schematic should create a service class 1`] = `
11-
"import { Injectable } from '@angular/core';
11+
"import { Injectable, inject } from '@angular/core';
1212
import {
1313
EntityCollectionServiceBase,
1414
EntityCollectionServiceElementsFactory
@@ -17,8 +17,8 @@ import { Foo } from './foo';
1717
1818
@Injectable({ providedIn: 'root' })
1919
export class FooService extends EntityCollectionServiceBase<Foo> {
20-
constructor(serviceElementsFactory: EntityCollectionServiceElementsFactory) {
21-
super('Foo', serviceElementsFactory);
20+
constructor() {
21+
super('Foo', inject(EntityCollectionServiceElementsFactory));
2222
}
2323
}
2424
"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable, inject } from '@angular/core';
22
import {
33
EntityCollectionServiceBase,
44
EntityCollectionServiceElementsFactory
@@ -7,7 +7,7 @@ import { <%= classify(name) %> } from './<%= dasherize(name) %>';
77

88
@Injectable({ providedIn: 'root' })
99
export class <%= classify(name) %>Service extends EntityCollectionServiceBase<<%= classify(name) %>> {
10-
constructor(serviceElementsFactory: EntityCollectionServiceElementsFactory) {
11-
super('<%= classify(name) %>', serviceElementsFactory);
10+
constructor() {
11+
super('<%= classify(name) %>', inject(EntityCollectionServiceElementsFactory));
1212
}
1313
}

modules/schematics/src/effect/__snapshots__/index.spec.ts.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { FooEffects } from './foo/foo.effects';
2525
`;
2626

2727
exports[`Effect Schematic feature effects should create an effect that describes a source of actions within a feature 1`] = `
28-
"import { Injectable } from '@angular/core';
28+
"import { Injectable, inject } from '@angular/core';
2929
import { Actions, createEffect, ofType } from '@ngrx/effects';
3030
3131
import { concatMap } from 'rxjs/operators';
@@ -34,6 +34,7 @@ import { FooActions } from './foo.actions';
3434
3535
@Injectable()
3636
export class FooEffects {
37+
private actions$ = inject(Actions);
3738
3839
3940
loadFoos$ = createEffect(() => {
@@ -45,7 +46,6 @@ export class FooEffects {
4546
);
4647
});
4748
48-
constructor(private actions$: Actions) {}
4949
}
5050
"
5151
`;
@@ -146,16 +146,16 @@ import { FooEffects } from './foo/foo.effects';
146146
`;
147147

148148
exports[`Effect Schematic root effects should create an effect that does not define a source of actions within the root 1`] = `
149-
"import { Injectable } from '@angular/core';
149+
"import { Injectable, inject } from '@angular/core';
150150
import { Actions, createEffect } from '@ngrx/effects';
151151
152152
153153
154154
@Injectable()
155155
export class FooEffects {
156+
private actions$ = inject(Actions);
156157
157158
158-
constructor(private actions$: Actions) {}
159159
}
160160
"
161161
`;
@@ -210,7 +210,7 @@ export class AppModule { }
210210
`;
211211

212212
exports[`Effect Schematic should add prefix to the effect 1`] = `
213-
"import { Injectable } from '@angular/core';
213+
"import { Injectable, inject } from '@angular/core';
214214
import { Actions, createEffect, ofType } from '@ngrx/effects';
215215
import { catchError, map, concatMap } from 'rxjs/operators';
216216
import { Observable, EMPTY, of } from 'rxjs';
@@ -219,6 +219,7 @@ import { FooActions } from './foo.actions';
219219
220220
@Injectable()
221221
export class FooEffects {
222+
private actions$ = inject(Actions);
222223
223224
customFoos$ = createEffect(() => {
224225
return this.actions$.pipe(
@@ -234,13 +235,12 @@ export class FooEffects {
234235
});
235236
236237
237-
constructor(private actions$: Actions) {}
238238
}
239239
"
240240
`;
241241

242242
exports[`Effect Schematic should create an api effect that describes a source of actions within a feature 1`] = `
243-
"import { Injectable } from '@angular/core';
243+
"import { Injectable, inject } from '@angular/core';
244244
import { Actions, createEffect, ofType } from '@ngrx/effects';
245245
import { catchError, map, concatMap } from 'rxjs/operators';
246246
import { Observable, EMPTY, of } from 'rxjs';
@@ -249,6 +249,7 @@ import { FooActions } from './foo.actions';
249249
250250
@Injectable()
251251
export class FooEffects {
252+
private actions$ = inject(Actions);
252253
253254
loadFoos$ = createEffect(() => {
254255
return this.actions$.pipe(
@@ -264,13 +265,12 @@ export class FooEffects {
264265
});
265266
266267
267-
constructor(private actions$: Actions) {}
268268
}
269269
"
270270
`;
271271

272272
exports[`Effect Schematic should group and nest the effect within a feature 1`] = `
273-
"import { Injectable } from '@angular/core';
273+
"import { Injectable, inject } from '@angular/core';
274274
import { Actions, createEffect, ofType } from '@ngrx/effects';
275275
276276
import { concatMap } from 'rxjs/operators';
@@ -279,6 +279,7 @@ import { FooActions } from '../../actions/foo/foo.actions';
279279
280280
@Injectable()
281281
export class FooEffects {
282+
private actions$ = inject(Actions);
282283
283284
284285
loadFoos$ = createEffect(() => {
@@ -290,7 +291,6 @@ export class FooEffects {
290291
);
291292
});
292293
293-
constructor(private actions$: Actions) {}
294294
}
295295
"
296296
`;

modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable, inject } from '@angular/core';
22
import { Actions, <%= effectMethod %><% if (feature) { %>, ofType<% } %> } from '@ngrx/effects';
33
<% if (feature && api) { %>import { catchError, map, concatMap } from 'rxjs/operators';
44
import { Observable, EMPTY, of } from 'rxjs';
@@ -9,6 +9,7 @@ import { <%= classify(name) %>Actions } from '<%= featurePath(group, flat, "acti
99

1010
@Injectable()
1111
export class <%= classify(name) %>Effects {
12+
private actions$ = inject(Actions);
1213
<% if (feature && api) { %>
1314
<%= effectStart %>
1415
ofType(<%= classify(name) %>Actions.<%= prefix %><%= classify(name) %>s),
@@ -27,5 +28,4 @@ export class <%= classify(name) %>Effects {
2728
concatMap(() => EMPTY as Observable<{ type: string }>)
2829
<%= effectEnd %>
2930
<% } %>
30-
constructor(private actions$: Actions) {}
3131
}

modules/schematics/src/feature/__snapshots__/index.spec.ts.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('Foo Reducer', () => {
111111
`;
112112
113113
exports[`Feature Schematic should create all files of a feature with an entity 4`] = `
114-
"import { Injectable } from '@angular/core';
114+
"import { Injectable, inject } from '@angular/core';
115115
import { Actions, createEffect, ofType } from '@ngrx/effects';
116116
117117
import { concatMap } from 'rxjs/operators';
@@ -120,6 +120,7 @@ import { FooActions } from './foo.actions';
120120
121121
@Injectable()
122122
export class FooEffects {
123+
private actions$ = inject(Actions);
123124
124125
125126
loadFoos$ = createEffect(() => {
@@ -131,7 +132,6 @@ export class FooEffects {
131132
);
132133
});
133134
134-
constructor(private actions$: Actions) {}
135135
}
136136
"
137137
`;
@@ -231,7 +231,7 @@ export const fooFeature = createFeature({
231231
`;
232232
233233
exports[`Feature Schematic should have all api effect if api flag enabled 1`] = `
234-
"import { Injectable } from '@angular/core';
234+
"import { Injectable, inject } from '@angular/core';
235235
import { Actions, createEffect, ofType } from '@ngrx/effects';
236236
import { catchError, map, concatMap } from 'rxjs/operators';
237237
import { Observable, EMPTY, of } from 'rxjs';
@@ -240,6 +240,7 @@ import { FooActions } from './foo.actions';
240240
241241
@Injectable()
242242
export class FooEffects {
243+
private actions$ = inject(Actions);
243244
244245
loadFoos$ = createEffect(() => {
245246
return this.actions$.pipe(
@@ -255,13 +256,12 @@ export class FooEffects {
255256
});
256257
257258
258-
constructor(private actions$: Actions) {}
259259
}
260260
"
261261
`;
262262
263263
exports[`Feature Schematic should have all api effect with prefix if api flag enabled 1`] = `
264-
"import { Injectable } from '@angular/core';
264+
"import { Injectable, inject } from '@angular/core';
265265
import { Actions, createEffect, ofType } from '@ngrx/effects';
266266
import { catchError, map, concatMap } from 'rxjs/operators';
267267
import { Observable, EMPTY, of } from 'rxjs';
@@ -270,6 +270,7 @@ import { FooActions } from './foo.actions';
270270
271271
@Injectable()
272272
export class FooEffects {
273+
private actions$ = inject(Actions);
273274
274275
customFoos$ = createEffect(() => {
275276
return this.actions$.pipe(
@@ -285,7 +286,6 @@ export class FooEffects {
285286
});
286287
287288
288-
constructor(private actions$: Actions) {}
289289
}
290290
"
291291
`;

0 commit comments

Comments
 (0)