Skip to content

Commit

Permalink
fix(schematics): assert empty as action observable (#3005)
Browse files Browse the repository at this point in the history
Closes #2931
  • Loading branch information
timdeschryver authored Apr 29, 2021
1 parent d673048 commit 61b1ac7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable } from '@angular/core';
import { Actions, <%= effectMethod %><% if (feature) { %>, ofType<% } %> } from '@ngrx/effects';
<% if (feature && api) { %>import { catchError, map, concatMap } from 'rxjs/operators';
import { EMPTY, of } from 'rxjs';
import { Observable, EMPTY, of } from 'rxjs';
<% if (!creators) {%>import { Load<%= classify(name) %>sFailure, Load<%= classify(name) %>sSuccess, <%= classify(name) %>ActionTypes, <%= classify(name) %>Actions } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %>
<% if (creators) {%>import * as <%= classify(name) %>Actions from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %>
<% } %>
<% if (feature && !api) { %>import { concatMap } from 'rxjs/operators';
import { EMPTY } from 'rxjs';
import { Observable, EMPTY } from 'rxjs';
<% if (!creators) {%>import { <%= classify(name) %>ActionTypes, <%= classify(name) %>Actions } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %>
<% if (creators) {%>import * as <%= classify(name) %>Actions from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %>
<% } %>
Expand Down Expand Up @@ -38,13 +38,13 @@ export class <%= classify(name) %>Effects {
<%= effectStart %>
ofType(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s),
/** An EMPTY observable only emits completion. Replace with your own observable API request */
concatMap(() => EMPTY)
concatMap(() => EMPTY as Observable<{ type: string }>)
<%= effectEnd %>
<% } else if (feature && !api && creators) { %>
<%= effectStart %>
ofType(<%= classify(name) %>Actions.load<%= classify(name) %>s),
/** An EMPTY observable only emits completion. Replace with your own observable API request */
concatMap(() => EMPTY)
concatMap(() => EMPTY as Observable<{ type: string }>)
<%= effectEnd %>
<% } %>
<% if (feature && !creators) { %>
Expand Down
8 changes: 5 additions & 3 deletions modules/schematics/src/effect/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,16 @@ describe('Effect Schematic', () => {
/import { Actions, Effect, ofType } from '@ngrx\/effects';/
);
expect(content).toMatch(/import { concatMap } from 'rxjs\/operators';/);
expect(content).toMatch(/import { EMPTY } from 'rxjs';/);
expect(content).toMatch(/import { Observable, EMPTY } from 'rxjs';/);
expect(content).toMatch(
/import { FooActionTypes, FooActions } from '\.\/foo.actions';/
);
expect(content).toMatch(/export class FooEffects/);
expect(content).toMatch(/loadFoos\$ = this\.actions\$.pipe\(/);
expect(content).toMatch(/ofType\(FooActionTypes\.LoadFoos\)/);
expect(content).toMatch(/concatMap\(\(\) => EMPTY\)/);
expect(content).toMatch(
/concatMap\(\(\) => EMPTY as Observable<\{ type: string \}>\)/
);

expect(content).toMatch(
/constructor\(private actions\$: Actions<FooActions>\) {}/
Expand Down Expand Up @@ -371,7 +373,7 @@ describe('Effect Schematic', () => {
expect(content).toMatch(
/import { catchError, map, concatMap } from 'rxjs\/operators';/
);
expect(content).toMatch(/import { EMPTY, of } from 'rxjs';/);
expect(content).toMatch(/import { Observable, EMPTY, of } from 'rxjs';/);
expect(content).toMatch(
/import { LoadFoosFailure, LoadFoosSuccess, FooActionTypes, FooActions } from '\.\/foo.actions';/
);
Expand Down
4 changes: 3 additions & 1 deletion modules/schematics/src/feature/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ describe('Feature Schematic', () => {
expect(fileContent).toMatch(
/import { catchError, map, concatMap } from 'rxjs\/operators';/
);
expect(fileContent).toMatch(/import { EMPTY, of } from 'rxjs';/);
expect(fileContent).toMatch(
/import { Observable, EMPTY, of } from 'rxjs';/
);
expect(fileContent).toMatch(
/import \* as FooActions from '.\/foo.actions';/
);
Expand Down

0 comments on commit 61b1ac7

Please sign in to comment.