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,6 +1,6 @@
import { Injectable } from '@angular/core';
import { Actions, Effect } from '@ngrx/effects';
<% if(feature) { %>import { <%= classify(name) %>Actions, <%= classify(name) %>ActionTypes } from '<%= featurePath(group, "actions") %><%= dasherize(name) %>.actions';<% } %>
<% if(feature) { %>import { <%= classify(name) %>Actions, <%= classify(name) %>ActionTypes } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %>

@Injectable()
export class <%= classify(name) %>Effects {
Expand Down
22 changes: 22 additions & 0 deletions modules/schematics/src/effect/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,26 @@ describe('Effect Schematic', () => {
files.indexOf('/src/app/effects/foo.effects.ts')
).toBeGreaterThanOrEqual(0);
});

it('should group and nest the effect within a feature', () => {
const options = {
...defaultOptions,
spec: false,
group: true,
flat: false,
feature: true,
};

const tree = schematicRunner.runSchematic('effect', options, appTree);
const files = tree.files;
expect(
files.indexOf('/src/app/effects/foo/foo.effects.ts')
).toBeGreaterThanOrEqual(0);

const content = getFileContent(tree, '/src/app/effects/foo/foo.effects.ts');

expect(content).toMatch(
/import\ \{\ FooActions,\ FooActionTypes\ }\ from\ \'\.\.\/\.\.\/actions\/foo\/foo\.actions';/
);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Action } from '@ngrx/store';
<% if(feature) { %>import { <%= classify(name) %>Actions, <%= classify(name) %>ActionTypes } from '<%= featurePath(group, "actions") %><%= dasherize(name) %>.actions';<% } %>
<% if(feature) { %>import { <%= classify(name) %>Actions, <%= classify(name) %>ActionTypes } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %>

export interface State {

Expand Down
25 changes: 25 additions & 0 deletions modules/schematics/src/reducer/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,29 @@ describe('Reducer Schematic', () => {
expect(tree.files.length).toEqual(1);
expect(tree.files[0]).toEqual('/src/app/reducers/foo.reducer.ts');
});

it('should group and nest the reducer within a feature', () => {
const options = {
...defaultOptions,
spec: false,
group: true,
flat: false,
feature: true,
};

const tree = schematicRunner.runSchematic('reducer', options, appTree);
const files = tree.files;
expect(
files.indexOf('/src/app/reducers/foo/foo.reducer.ts')
).toBeGreaterThanOrEqual(0);

const content = getFileContent(
tree,
'/src/app/reducers/foo/foo.reducer.ts'
);

expect(content).toMatch(
/import\ \{\ FooActions,\ FooActionTypes\ }\ from\ \'\.\.\/\.\.\/actions\/foo\/foo\.actions';/
);
});
});
15 changes: 12 additions & 3 deletions modules/schematics/src/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,19 @@ export function capitalize(str: string): string {
return str.charAt(0).toUpperCase() + str.substr(1);
}

export function group(path: string, group: string | undefined) {
return group ? `${group}/${path}` : path;
export function group(name: string, group: string | undefined) {
return group ? `${group}/${name}` : name;
}

export function featurePath(group: boolean | undefined, path: string) {
export function featurePath(
group: boolean | undefined,
flat: boolean | undefined,
path: string,
name: string
) {
if (group && !flat) {
return `../../${path}/${name}/`;
}

return group ? `../${path}/` : './';
}