Skip to content

Commit 77f2d0a

Browse files
authored
fix(angular): generate ngrx code using rxjs operators from rxjs/operators when workspace has rxjs <7.2.0 (#15977)
1 parent 6eca9b6 commit 77f2d0a

16 files changed

+84
-30
lines changed

packages/angular/src/generators/ngrx/__snapshots__/ngrx.spec.ts.snap

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,10 @@ export const loadUsersFailure = createAction(
402402
exports[`ngrx NgModule Syntax should generate the ngrx effects 1`] = `
403403
"import { Injectable, inject } from '@angular/core';
404404
import { createEffect, Actions, ofType } from '@ngrx/effects';
405-
405+
import { switchMap, catchError, of } from 'rxjs';
406406
import * as UsersActions from './users.actions';
407407
import * as UsersFeature from './users.reducer';
408408
409-
import { switchMap, catchError, of } from 'rxjs';
410-
411409
@Injectable()
412410
export class UsersEffects {
413411
private actions$ = inject(Actions);
@@ -756,12 +754,10 @@ export const appRoutes: Routes = [
756754
exports[`ngrx angular v14 support should generate the ngrx effects using "inject" for versions >= 14.1.0 1`] = `
757755
"import { Injectable, inject } from '@angular/core';
758756
import { createEffect, Actions, ofType } from '@ngrx/effects';
759-
757+
import { switchMap, catchError, of } from 'rxjs';
760758
import * as UsersActions from './users.actions';
761759
import * as UsersFeature from './users.reducer';
762760
763-
import { switchMap, catchError, of } from 'rxjs';
764-
765761
@Injectable()
766762
export class UsersEffects {
767763
private actions$ = inject(Actions);
@@ -868,3 +864,29 @@ export class UsersFacade {
868864
}
869865
"
870866
`;
867+
868+
exports[`ngrx rxjs v6 support should generate the ngrx effects using rxjs operators imported from "rxjs/operators" 1`] = `
869+
"import { Injectable, inject } from '@angular/core';
870+
import { createEffect, Actions, ofType } from '@ngrx/effects';
871+
import { of } from 'rxjs';
872+
import { switchMap, catchError } from 'rxjs/operators';
873+
import * as UsersActions from './users.actions';
874+
import * as UsersFeature from './users.reducer';
875+
876+
@Injectable()
877+
export class UsersEffects {
878+
private actions$ = inject(Actions);
879+
880+
init$ = createEffect(() =>
881+
this.actions$.pipe(
882+
ofType(UsersActions.initUsers),
883+
switchMap(() => of(UsersActions.loadUsersSuccess({ users: [] }))),
884+
catchError((error) => {
885+
console.error('Error', error);
886+
return of(UsersActions.loadUsersFailure({ error }));
887+
})
888+
)
889+
);
890+
}
891+
"
892+
`;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Injectable, inject } from '@angular/core';
2-
import { createEffect, Actions, ofType } from '@ngrx/effects';
3-
2+
import { createEffect, Actions, ofType } from '@ngrx/effects';<% if (!importFromOperators) { %>
3+
import { switchMap, catchError, of } from 'rxjs';<% } else { %>
4+
import { of } from 'rxjs';
5+
import { switchMap, catchError } from 'rxjs/operators';<% } %>
46
import * as <%= className %>Actions from './<%= fileName %>.actions';
57
import * as <%= className %>Feature from './<%= fileName %>.reducer';
68

7-
import {switchMap, catchError, of} from 'rxjs';
8-
99
@Injectable()
1010
export class <%= className %>Effects {
1111
private actions$ = inject(Actions);

0 commit comments

Comments
 (0)