Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Injectable } from '@angular/core';
import { Actions, Effect<% if (feature) { %>, ofType<% } %> } from '@ngrx/effects';
<% if (feature && api) { %>import { catchError, map, concatMap } from 'rxjs/operators';<% } %>
<% if (feature && api) { %>import { EMPTY, of } from 'rxjs';<% } %>
<% if (feature && api) { %>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 (feature && !api) { %>import { <%= classify(name) %>ActionTypes } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %>
<% if (feature && api) { %>import { catchError, map, concatMap } from 'rxjs/operators';
import { EMPTY, of } from 'rxjs';
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 (feature && !api) { %>import { concatMap } from 'rxjs/operators';
import { EMPTY } from 'rxjs';
import { <%= classify(name) %>ActionTypes, <%= classify(name) %>Actions } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';
<% } %>

@Injectable()
export class <%= classify(name) %>Effects {
Expand All @@ -17,13 +21,16 @@ export class <%= classify(name) %>Effects {
map(data => new Load<%= classify(name) %>sSuccess({ data })),
catchError(error => of(new Load<%= classify(name) %>sFailure({ error }))))
)
);
<% } %>
);<% } %>
<% if (feature && !api) { %>
@Effect()
load<%= classify(name) %>s$ = this.actions$.pipe(ofType(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s));
load<%= classify(name) %>s$ = this.actions$.pipe(
ofType(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s),
/** An EMPTY observable only emits completion. Replace with your own observable API request */
concatMap(() => EMPTY)
);
<% } %>
<% if (feature && api) { %>
<% if (feature) { %>
constructor(private actions$: Actions<<%= classify(name) %>Actions>) {}
<% } else { %>
constructor(private actions$: Actions) {}
Expand Down
14 changes: 10 additions & 4 deletions modules/schematics/src/effect/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describe('Effect Schematic', () => {
);

expect(content).toMatch(
/import \{ FooActionTypes } from \'\.\.\/\.\.\/actions\/foo\/foo\.actions';/
/import \{ FooActionTypes, FooActions } from \'\.\.\/\.\.\/actions\/foo\/foo\.actions';/
);
});

Expand All @@ -250,12 +250,18 @@ describe('Effect Schematic', () => {
expect(content).toMatch(
/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 { FooActionTypes } from '\.\/foo.actions';/
/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(
/loadFoos\$ = this\.actions\$.pipe\(ofType\(FooActionTypes\.LoadFoos\)\);/
/constructor\(private actions\$: Actions<FooActions>\) {}/
);
});

Expand All @@ -274,7 +280,7 @@ describe('Effect Schematic', () => {
);
expect(content).toMatch(/export class FooEffects/);
expect(content).not.toMatch(
/loadFoos\$ = this\.actions\$.pipe\(ofType\(FooActionTypes\.LoadFoos\)\);/
/loadFoos\$ = this\.actions\$.pipe\(ofType\(FooActionTypes\.LoadFoos/
);
});

Expand Down