Skip to content

Commit

Permalink
feat(schematics): enable immutability checks for root store by default (
Browse files Browse the repository at this point in the history
#1983)

Closes #1950
  • Loading branch information
itayod authored and brandonroberts committed Jul 1, 2019
1 parent dcb5a27 commit 2b8178d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions modules/schematics/src/store/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,14 @@ describe('Store Schematic', () => {
schematicRunner.runSchematic('store', options, appTree);
}).not.toThrow();
});

it('should add store runtime checks', () => {
const options = { ...defaultOptions, module: 'app.module.ts' };

const tree = schematicRunner.runSchematic('store', options, appTree);
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
expect(content).toMatch(/, runtimeChecks: {/);
expect(content).toMatch(/strictStateImmutability: true,/);
expect(content).toMatch(/strictActionImmutability: true/);
});
});
7 changes: 6 additions & 1 deletion modules/schematics/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ function addImportToNgModule(options: StoreOptions): Rule {
`${options.path}/environments/environment`
);

const runtimeChecks = `runtimeChecks: {
strictStateImmutability: true,
strictActionImmutability: true,
}`;

const storeNgModuleImport = addImportToModule(
source,
modulePath,
options.root
? `StoreModule.forRoot(reducers, { metaReducers })`
? `StoreModule.forRoot(reducers, { metaReducers, ${runtimeChecks} })`
: `StoreModule.forFeature('${stringUtils.camelize(
options.name
)}', from${stringUtils.classify(
Expand Down

0 comments on commit 2b8178d

Please sign in to comment.