Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(angular): update defaults for NgRx schematics #2443

Merged
merged 1 commit into from Feb 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/angular/api-angular/schematics/ngrx.md
Expand Up @@ -50,7 +50,7 @@ Create a Facade class for the the Feature.

### minimal

Default: `false`
Default: `true`

Type: `boolean`

Expand Down Expand Up @@ -118,7 +118,7 @@ Do not update the package.json with NgRx dependencies.

### syntax

Default: `classes`
Default: `creators`

Type: `string`

Expand All @@ -128,7 +128,7 @@ Specifies whether to use class-based or creator functions for actions, reducers,

### useDataPersistence

Default: `true`
Default: `false`

Type: `boolean`

Expand Down
4 changes: 2 additions & 2 deletions docs/angular/guides/misc-ngrx.md
Expand Up @@ -46,7 +46,7 @@ To get started with NgRx in an Angular application, you set up the root level st
The example below shows you how to setup NgRx in the root of your application.

```bash
ng g @nrwl/angular:ngrx app --module=apps/<appname>/src/app/app.module.ts --root --minimal
ng g @nrwl/angular:ngrx app --module=apps/<appname>/src/app/app.module.ts --root
```

The above command applies the following changes to the provided module:
Expand Down Expand Up @@ -75,7 +75,7 @@ To manage the feature state:
- Provide a path to the `products` library module.

```bash
ng g @nrwl/angular:ngrx products --module=libs/products/src/lib/products.module.ts --directory +state/products --syntax=creators --defaults
ng g @nrwl/angular:ngrx products --module=libs/products/src/lib/products.module.ts --directory +state/products --defaults
```

> Use the `--facade` option to generate an injectable Facade class along with the feature.
Expand Down
6 changes: 3 additions & 3 deletions docs/react/api-angular/schematics/ngrx.md
Expand Up @@ -50,7 +50,7 @@ Create a Facade class for the the Feature.

### minimal

Default: `false`
Default: `true`

Type: `boolean`

Expand Down Expand Up @@ -118,7 +118,7 @@ Do not update the package.json with NgRx dependencies.

### syntax

Default: `classes`
Default: `creators`

Type: `string`

Expand All @@ -128,7 +128,7 @@ Specifies whether to use class-based or creator functions for actions, reducers,

### useDataPersistence

Default: `true`
Default: `false`

Type: `boolean`

Expand Down
6 changes: 3 additions & 3 deletions docs/web/api-angular/schematics/ngrx.md
Expand Up @@ -50,7 +50,7 @@ Create a Facade class for the the Feature.

### minimal

Default: `false`
Default: `true`

Type: `boolean`

Expand Down Expand Up @@ -118,7 +118,7 @@ Do not update the package.json with NgRx dependencies.

### syntax

Default: `classes`
Default: `creators`

Type: `string`

Expand All @@ -128,7 +128,7 @@ Specifies whether to use class-based or creator functions for actions, reducers,

### useDataPersistence

Default: `true`
Default: `false`

Type: `boolean`

Expand Down
8 changes: 4 additions & 4 deletions e2e/ngrx.test.ts
Expand Up @@ -18,7 +18,7 @@ forEachCli(() => {

// Generate root ngrx state management
runCLI(
`generate @nrwl/angular:ngrx users --module=apps/${myapp}/src/app/app.module.ts --root`
`generate @nrwl/angular:ngrx users --module=apps/${myapp}/src/app/app.module.ts --root --minimal=false --syntax=classes --useDataPersistence=true`
);
const packageJson = readJson('package.json');
expect(packageJson.dependencies['@ngrx/store']).toBeDefined();
Expand All @@ -30,7 +30,7 @@ forEachCli(() => {
// Generate feature library and ngrx state within that library
runCLI(`g @nrwl/angular:lib ${mylib} --prefix=fl`);
runCLI(
`generate @nrwl/angular:ngrx flights --module=libs/${mylib}/src/lib/${mylib}.module.ts --facade`
`generate @nrwl/angular:ngrx flights --module=libs/${mylib}/src/lib/${mylib}.module.ts --facade --syntax=classes`
);

expect(runCLI(`build ${myapp}`)).toContain(
Expand All @@ -51,7 +51,7 @@ forEachCli(() => {

// Generate root ngrx state management
runCLI(
`generate @nrwl/angular:ngrx users --module=apps/${myapp}/src/app/app.module.ts --root --minimal --syntax=creators`
`generate @nrwl/angular:ngrx users --module=apps/${myapp}/src/app/app.module.ts --root`
);
const packageJson = readJson('package.json');
expect(packageJson.dependencies['@ngrx/entity']).toBeDefined();
Expand All @@ -65,7 +65,7 @@ forEachCli(() => {
// Generate feature library and ngrx state within that library
runCLI(`g @nrwl/angular:lib ${mylib} --prefix=fl`);

const flags = `--facade --syntax=creators --useDataPersistence=false --barrels`;
const flags = `--facade --barrels`;
runCLI(
`generate @nrwl/angular:ngrx flights --module=libs/${mylib}/src/lib/${mylib}.module.ts ${flags}`
);
Expand Down
38 changes: 26 additions & 12 deletions packages/angular/src/schematics/ngrx/ngrx.spec.ts
Expand Up @@ -29,7 +29,9 @@ describe('ngrx', () => {
{
name: 'state',
module: 'apps/myapp/src/app/app.module.ts',
onlyEmptyRoot: true
onlyEmptyRoot: true,
minimal: false,
root: true
},
appTree
);
Expand Down Expand Up @@ -77,7 +79,8 @@ describe('ngrx', () => {
{
name: 'app',
module: 'apps/myapp/src/app/app.module.ts',
root: true
root: true,
minimal: false
},
appTree
);
Expand Down Expand Up @@ -124,7 +127,8 @@ describe('ngrx', () => {
name: 'app',
module: 'apps/myapp/src/app/app.module.ts',
root: true,
facade: true
facade: true,
minimal: false
},
appTree
);
Expand Down Expand Up @@ -180,7 +184,8 @@ describe('ngrx', () => {
'ngrx',
{
name: 'state',
module: 'apps/myapp/src/app/app.module.ts'
module: 'apps/myapp/src/app/app.module.ts',
minimal: false
},
appTree
);
Expand All @@ -201,7 +206,8 @@ describe('ngrx', () => {
{
name: 'state',
module: 'apps/myapp/src/app/app.module.ts',
directory: 'myCustomState'
directory: 'myCustomState',
minimal: false
},
appTree
);
Expand All @@ -223,7 +229,8 @@ describe('ngrx', () => {
name: 'state',
module: 'apps/myapp/src/app/app.module.ts',
onlyAddFiles: true,
facade: true
facade: true,
minimal: false
},
appTree
);
Expand Down Expand Up @@ -253,7 +260,8 @@ describe('ngrx', () => {
module: 'apps/myapp/src/app/app.module.ts',
onlyAddFiles: false,
skipImport: true,
facade: true
facade: true,
minimal: false
},
appTree
);
Expand Down Expand Up @@ -519,7 +527,8 @@ import {
'ngrx',
{
name: 'super-users',
module: appConfig.appModule
module: appConfig.appModule,
minimal: false
},
appTree
);
Expand Down Expand Up @@ -549,7 +558,9 @@ import {
name: 'users',
module: appConfig.appModule,
syntax: 'creators',
facade: true
minimal: false,
facade: true,
useDataPersistance: false
},
appTree
);
Expand Down Expand Up @@ -588,7 +599,7 @@ import {

[
`import { createEffect, Actions, ofType } from '@ngrx/effects';`,
'this.dataPersistence.fetch(UsersActions.loadUsers, {'
'fetch({'
].forEach(text => {
expect(content).toContain(text);
});
Expand Down Expand Up @@ -645,7 +656,7 @@ import {
module: appConfig.appModule,
syntax: 'creators',
facade: true,
useDataPersistence: false
minimal: false
},
appTree
);
Expand Down Expand Up @@ -701,7 +712,10 @@ import {
{
name: featureName,
module: appConfig.appModule,
facade: withFacade
facade: withFacade,
syntax: 'classes',
minimal: false,
useDataPersistance: true
},
appTree
);
Expand Down
7 changes: 4 additions & 3 deletions packages/angular/src/schematics/ngrx/ngrx.ts
Expand Up @@ -54,9 +54,10 @@ export default function generateNgrxCollection(_options: Schema): Rule {
options.onlyAddFiles = true;
}

const fileGeneration = !options.onlyEmptyRoot
? [generateNgrxFilesFromTemplates(options)]
: [];
const fileGeneration =
!options.onlyEmptyRoot || (!options.root && options.minimal)
? [generateNgrxFilesFromTemplates(options)]
: [];

const moduleModification = !options.onlyAddFiles
? [
Expand Down
Expand Up @@ -70,7 +70,10 @@ export function addImportsToModule(context: RequestContext): Rule {
const hasRouter = sourceText.indexOf('RouterModule') > -1;
const hasNxModule = sourceText.includes('NxModule.forRoot()');

if (context.options.onlyEmptyRoot || context.options.minimal) {
if (
(context.options.onlyEmptyRoot || context.options.minimal) &&
context.options.root
) {
insert(host, modulePath, [
addImport.apply(this, storeModule),
addImport.apply(this, effectsModule),
Expand Down
6 changes: 3 additions & 3 deletions packages/angular/src/schematics/ngrx/schema.json
Expand Up @@ -47,7 +47,7 @@
},
"minimal": {
"type": "boolean",
"default": false,
"default": true,
"description": "Only register the root state management setup or feature state."
},
"onlyEmptyRoot": {
Expand All @@ -68,12 +68,12 @@
"syntax": {
"type": "string",
"enum": ["classes", "creators"],
"default": "classes",
"default": "creators",
"description": "Specifies whether to use class-based or creator functions for actions, reducers, and effects."
},
"useDataPersistence": {
"type": "boolean",
"default": true,
"default": false,
"description": "Generate NgRx Effects with the DataPersistence helper service. Set to false to use plain effects data persistence operators."
},
"barrels": {
Expand Down