Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Schematics): use ofType operator function instead of Actions#ofType #1154

Merged
Show file tree
Hide file tree
Changes from 5 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,12 +1,12 @@
import { Injectable } from '@angular/core';
import { Actions, Effect } from '@ngrx/effects';
<% if(feature) { %>import { <%= classify(name) %>Actions, <%= classify(name) %>ActionTypes } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %>
import { Actions, Effect<% if (feature) { %>, ofType<% } %> } from '@ngrx/effects';
<% if (feature) { %>import { Load<%= classify(name) %>s, <%= classify(name) %>ActionTypes } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %>

@Injectable()
export class <%= classify(name) %>Effects {
<% if(feature) { %>
<% if (feature) { %>
@Effect()
effect$ = this.actions$.ofType(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s);
loadFoos$ = this.actions$.pipe(ofType<Load<%= classify(name) %>s>(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s));
<% } %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the <Load<%= classify(name) %>s>

constructor(private actions$: Actions) {}
}
42 changes: 40 additions & 2 deletions modules/schematics/src/effect/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Effect Schematic', () => {
appTree = createWorkspace(schematicRunner, appTree);
});

it('should create an effect', () => {
it('should create an effect with a spec file', () => {
const options = { ...defaultOptions };

const tree = schematicRunner.runSchematic('effect', options, appTree);
Expand Down Expand Up @@ -215,7 +215,45 @@ describe('Effect Schematic', () => {
);

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

it('should create an effect that describes a source of actions within a feature', () => {
const options = { ...defaultOptions, feature: true };

const tree = schematicRunner.runSchematic('effect', options, appTree);
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.effects.ts`
);
expect(content).toMatch(
/import { Actions, Effect, ofType } from '@ngrx\/effects';/
);
expect(content).toMatch(
/import { LoadFoos, FooActionTypes } from '\.\/foo.actions';/
);
expect(content).toMatch(/export class FooEffects/);
expect(content).toMatch(
/loadFoos\$ = this\.actions\$.pipe\(ofType<LoadFoos>\(FooActionTypes\.LoadFoos\)\);/
);
});

it('should create an effect that does not define a source of actions within the root', () => {
const options = { ...defaultOptions, root: true };

const tree = schematicRunner.runSchematic('effect', options, appTree);
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.effects.ts`
);
expect(content).toMatch(
/import { Actions, Effect } from '@ngrx\/effects';/
);
expect(content).not.toMatch(
/import { LoadFoos, FooActionTypes } from '\.\/foo.actions';/
);
expect(content).toMatch(/export class FooEffects/);
expect(content).not.toMatch(
/loadFoos\$ = this\.actions\$.pipe\(ofType<LoadFoos>\(FooActionTypes\.LoadFoos\)\);/
);
});
});