Skip to content

Commit 2b8178d

Browse files
itayodbrandonroberts
authored andcommitted
feat(schematics): enable immutability checks for root store by default (#1983)
Closes #1950
1 parent dcb5a27 commit 2b8178d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,14 @@ describe('Store Schematic', () => {
238238
schematicRunner.runSchematic('store', options, appTree);
239239
}).not.toThrow();
240240
});
241+
242+
it('should add store runtime checks', () => {
243+
const options = { ...defaultOptions, module: 'app.module.ts' };
244+
245+
const tree = schematicRunner.runSchematic('store', options, appTree);
246+
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
247+
expect(content).toMatch(/, runtimeChecks: {/);
248+
expect(content).toMatch(/strictStateImmutability: true,/);
249+
expect(content).toMatch(/strictActionImmutability: true/);
250+
});
241251
});

modules/schematics/src/store/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,16 @@ function addImportToNgModule(options: StoreOptions): Rule {
6161
`${options.path}/environments/environment`
6262
);
6363

64+
const runtimeChecks = `runtimeChecks: {
65+
strictStateImmutability: true,
66+
strictActionImmutability: true,
67+
}`;
68+
6469
const storeNgModuleImport = addImportToModule(
6570
source,
6671
modulePath,
6772
options.root
68-
? `StoreModule.forRoot(reducers, { metaReducers })`
73+
? `StoreModule.forRoot(reducers, { metaReducers, ${runtimeChecks} })`
6974
: `StoreModule.forFeature('${stringUtils.camelize(
7075
options.name
7176
)}', from${stringUtils.classify(

0 commit comments

Comments
 (0)