From 2b8178dd6161fc5c2c6386ecb3c16d89d0eda65b Mon Sep 17 00:00:00 2001 From: Itay Oded Date: Tue, 2 Jul 2019 02:19:41 +0300 Subject: [PATCH] feat(schematics): enable immutability checks for root store by default (#1983) Closes #1950 --- modules/schematics/src/store/index.spec.ts | 10 ++++++++++ modules/schematics/src/store/index.ts | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/schematics/src/store/index.spec.ts b/modules/schematics/src/store/index.spec.ts index 90363eebbf..0b24d48aa5 100644 --- a/modules/schematics/src/store/index.spec.ts +++ b/modules/schematics/src/store/index.spec.ts @@ -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/); + }); }); diff --git a/modules/schematics/src/store/index.ts b/modules/schematics/src/store/index.ts index 51c67a4935..a45e4da217 100644 --- a/modules/schematics/src/store/index.ts +++ b/modules/schematics/src/store/index.ts @@ -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(