Skip to content

Commit cb58ff1

Browse files
koumatsumotobrandonroberts
authored andcommitted
feat(schematics): use ofType operator function instead of Actions#ofType (#1154)
1 parent 221020a commit cb58ff1

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Injectable } from '@angular/core';
2-
import { Actions, Effect } from '@ngrx/effects';
3-
<% if(feature) { %>import { <%= classify(name) %>Actions, <%= classify(name) %>ActionTypes } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %>
2+
import { Actions, Effect<% if (feature) { %>, ofType<% } %> } from '@ngrx/effects';
3+
<% if (feature) { %>import { <%= classify(name) %>ActionTypes } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %>
44

55
@Injectable()
66
export class <%= classify(name) %>Effects {
7-
<% if(feature) { %>
7+
<% if (feature) { %>
88
@Effect()
9-
effect$ = this.actions$.ofType(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s);
9+
loadFoos$ = this.actions$.pipe(ofType(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s));
1010
<% } %>
1111
constructor(private actions$: Actions) {}
1212
}

modules/schematics/src/effect/index.spec.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('Effect Schematic', () => {
3737
appTree = createWorkspace(schematicRunner, appTree);
3838
});
3939

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

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

217217
expect(content).toMatch(
218-
/import\ \{\ FooActions,\ FooActionTypes\ }\ from\ \'\.\.\/\.\.\/actions\/foo\/foo\.actions';/
218+
/import \{ FooActionTypes } from \'\.\.\/\.\.\/actions\/foo\/foo\.actions';/
219+
);
220+
});
221+
222+
it('should create an effect that describes a source of actions within a feature', () => {
223+
const options = { ...defaultOptions, feature: true };
224+
225+
const tree = schematicRunner.runSchematic('effect', options, appTree);
226+
const content = tree.readContent(
227+
`${projectPath}/src/app/foo/foo.effects.ts`
228+
);
229+
expect(content).toMatch(
230+
/import { Actions, Effect, ofType } from '@ngrx\/effects';/
231+
);
232+
expect(content).toMatch(
233+
/import { FooActionTypes } from '\.\/foo.actions';/
234+
);
235+
expect(content).toMatch(/export class FooEffects/);
236+
expect(content).toMatch(
237+
/loadFoos\$ = this\.actions\$.pipe\(ofType\(FooActionTypes\.LoadFoos\)\);/
238+
);
239+
});
240+
241+
it('should create an effect that does not define a source of actions within the root', () => {
242+
const options = { ...defaultOptions, root: true };
243+
244+
const tree = schematicRunner.runSchematic('effect', options, appTree);
245+
const content = tree.readContent(
246+
`${projectPath}/src/app/foo/foo.effects.ts`
247+
);
248+
expect(content).toMatch(
249+
/import { Actions, Effect } from '@ngrx\/effects';/
250+
);
251+
expect(content).not.toMatch(
252+
/import { FooActionTypes } from '\.\/foo.actions';/
253+
);
254+
expect(content).toMatch(/export class FooEffects/);
255+
expect(content).not.toMatch(
256+
/loadFoos\$ = this\.actions\$.pipe\(ofType\(FooActionTypes\.LoadFoos\)\);/
219257
);
220258
});
221259
});

0 commit comments

Comments
 (0)