Skip to content

Commit f166a2b

Browse files
Merge pull request #200 from ngrx/master
Trackpad mode crash fix
2 parents 73ef859 + 3b9b890 commit f166a2b

File tree

8 files changed

+75
-19
lines changed

8 files changed

+75
-19
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,27 @@ describe('Store Schematic', () => {
215215
);
216216
expect(content).toMatch(/export interface FeatureState {/);
217217
});
218+
219+
it('should fail if a feature state name is not specified', () => {
220+
const options = {
221+
...defaultOptions,
222+
name: undefined,
223+
root: false,
224+
};
225+
226+
expect(() => {
227+
schematicRunner.runSchematic('store', options, appTree);
228+
}).toThrowError('Please provide a name for the feature state');
229+
});
230+
231+
it('should pass if a root state name is not specified', () => {
232+
const options = {
233+
...defaultOptions,
234+
name: undefined,
235+
};
236+
237+
expect(() => {
238+
schematicRunner.runSchematic('store', options, appTree);
239+
}).not.toThrow();
240+
});
218241
});

modules/schematics/src/store/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,13 @@ function addImportToNgModule(options: StoreOptions): Rule {
131131

132132
export default function(options: StoreOptions): Rule {
133133
return (host: Tree, context: SchematicContext) => {
134+
if (!options.name && !options.root) {
135+
throw new Error(`Please provide a name for the feature state`);
136+
}
137+
134138
options.path = getProjectPath(host, options);
135139

136-
const parsedPath = parseName(options.path, options.name);
140+
const parsedPath = parseName(options.path, options.name || '');
137141
options.name = parsedPath.name;
138142
options.path = parsedPath.path;
139143

projects/example-app/src/app/app.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ import { AppRoutingModule } from '@example-app/app-routing.module';
3333
* meta-reducer. This returns all providers for an @ngrx/store
3434
* based application.
3535
*/
36-
StoreModule.forRoot(reducers, { metaReducers }),
36+
StoreModule.forRoot(reducers, {
37+
metaReducers,
38+
runtimeChecks: {
39+
strictImmutability: true,
40+
},
41+
}),
3742

3843
/**
3944
* @ngrx/router-store keeps router state up-to-date in the store.

projects/example-app/src/app/auth/containers/login-page.component.spec.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ describe('Login Page', () => {
1717
TestBed.configureTestingModule({
1818
imports: [
1919
NoopAnimationsModule,
20-
StoreModule.forRoot({
21-
auth: combineReducers(fromAuth.reducers),
22-
}),
20+
StoreModule.forRoot(
21+
{
22+
auth: combineReducers(fromAuth.reducers),
23+
},
24+
{
25+
runtimeChecks: {
26+
strictImmutability: true,
27+
},
28+
}
29+
),
2330
MatInputModule,
2431
MatCardModule,
2532
ReactiveFormsModule,

projects/example-app/src/app/auth/reducers/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
import * as fromRoot from '@example-app/reducers';
77
import * as fromAuth from '@example-app/auth/reducers/auth.reducer';
88
import * as fromLoginPage from '@example-app/auth/reducers/login-page.reducer';
9-
import { AuthApiActions } from '@example-app/auth/actions';
109

1110
export interface AuthState {
1211
status: fromAuth.State;
@@ -17,10 +16,7 @@ export interface State extends fromRoot.State {
1716
auth: AuthState;
1817
}
1918

20-
export const reducers: ActionReducerMap<
21-
AuthState,
22-
AuthApiActions.AuthApiActionsUnion
23-
> = {
19+
export const reducers: ActionReducerMap<AuthState, any> = {
2420
status: fromAuth.reducer,
2521
loginPage: fromLoginPage.reducer,
2622
};

projects/example-app/src/app/books/containers/collection-page.component.spec.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@ describe('Collection Page', () => {
2121
TestBed.configureTestingModule({
2222
imports: [
2323
NoopAnimationsModule,
24-
StoreModule.forRoot({
25-
books: combineReducers(fromBooks.reducers),
26-
}),
24+
StoreModule.forRoot(
25+
{
26+
books: combineReducers(fromBooks.reducers),
27+
},
28+
{
29+
runtimeChecks: {
30+
strictImmutability: true,
31+
},
32+
}
33+
),
2734
MatCardModule,
2835
MatInputModule,
2936
RouterTestingModule,

projects/example-app/src/app/books/containers/find-book-page.component.spec.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ describe('Find Book Page', () => {
2828
TestBed.configureTestingModule({
2929
imports: [
3030
NoopAnimationsModule,
31-
StoreModule.forRoot({
32-
books: combineReducers(fromBooks.reducers),
33-
}),
31+
StoreModule.forRoot(
32+
{
33+
books: combineReducers(fromBooks.reducers),
34+
},
35+
{
36+
runtimeChecks: {
37+
strictImmutability: true,
38+
},
39+
}
40+
),
3441
RouterTestingModule,
3542
MatInputModule,
3643
MatCardModule,

projects/example-app/src/app/books/containers/selected-book-page.component.spec.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ describe('Selected Book Page', () => {
2020
TestBed.configureTestingModule({
2121
imports: [
2222
NoopAnimationsModule,
23-
StoreModule.forRoot({
24-
books: combineReducers(fromBooks.reducers),
25-
}),
23+
StoreModule.forRoot(
24+
{
25+
books: combineReducers(fromBooks.reducers),
26+
},
27+
{
28+
runtimeChecks: {
29+
strictImmutability: true,
30+
},
31+
}
32+
),
2633
MatCardModule,
2734
],
2835
declarations: [

0 commit comments

Comments
 (0)