Skip to content

Commit

Permalink
feat(schematics): use ofType operator function instead of Actions#ofT…
Browse files Browse the repository at this point in the history
…ype (#1154)
  • Loading branch information
koumatsumoto authored and brandonroberts committed Jun 29, 2018
1 parent 221020a commit cb58ff1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
@@ -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 { <%= 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(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s));
<% } %>
constructor(private actions$: Actions) {}
}
42 changes: 40 additions & 2 deletions modules/schematics/src/effect/index.spec.ts
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 \{ 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 { FooActionTypes } from '\.\/foo.actions';/
);
expect(content).toMatch(/export class FooEffects/);
expect(content).toMatch(
/loadFoos\$ = this\.actions\$.pipe\(ofType\(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 { FooActionTypes } from '\.\/foo.actions';/
);
expect(content).toMatch(/export class FooEffects/);
expect(content).not.toMatch(
/loadFoos\$ = this\.actions\$.pipe\(ofType\(FooActionTypes\.LoadFoos\)\);/
);
});
});

0 comments on commit cb58ff1

Please sign in to comment.