Skip to content

Commit

Permalink
refactor(schematics): Flag minimal is set to true (#2258)
Browse files Browse the repository at this point in the history
Closes #2250

BREAKING CHANGES:

With this change by default the minimal setup for `@ngrx/store` will be generated.

BEFORE:

```
@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    StoreModule.forRoot(reducers, {
      metaReducers,
      runtimeChecks: {
        strictStateImmutability: true,
        strictActionImmutability: true
      }
    }),
    .....
  ],
  providers: [],
  bootstrap: [AppComponent]
})
```

AFTER:

```
@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    StoreModule.forRoot({})
    ....
  ],
  providers: [],
  bootstrap: [AppComponent]
})
```
  • Loading branch information
Jefiozie authored and brandonroberts committed Jan 7, 2020
1 parent 41cc5fc commit 7ecaa22
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modules/store/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
SchematicTestRunner,
UnitTestTree,
} from '@angular-devkit/schematics/testing';
import { getFileContent } from '@schematics/angular/utility/test';
import * as path from 'path';
import { Schema as RootStoreOptions } from './schema';
import {
Expand All @@ -19,6 +18,7 @@ describe('Store ng-add Schematic', () => {
skipPackageJson: false,
project: 'bar',
module: 'app',
minimal: false,
};

const projectPath = getTestProjectPath();
Expand Down
2 changes: 1 addition & 1 deletion modules/store/schematics/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"minimal": {
"type": "boolean",
"default": false,
"default": true,
"description":
"Setup state management without registering initial reducers."
}
Expand Down
14 changes: 12 additions & 2 deletions projects/ngrx.io/content/guide/store/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,24 @@ ng add @ngrx/store
* path - path to the module that you wish to add the import for the `StoreModule` to.
* project - name of the project defined in your `angular.json` to help locating the module to add the `StoreModule` to.
* module - name of file containing the module that you wish to add the import for the `StoreModule` to. Can also include the relative path to the file. For example, `src/app/app.module.ts`;
* minimal - flag to only provide minimal setup for the root state management. Only registers `StoreModule.forRoot()` in the provided `module` with an empty object, and default runtime checks.
* minimal - By default true, flag to only provide minimal setup for the root state management. Only registers `StoreModule.forRoot()` in the provided `module` with an empty object, and default runtime checks.
* statePath - The file path to create the state in. By default, this is `reducers`.
* stateInterface - The type literal of the defined interface for the state. By default, this is `State`.

This command will automate the following steps:

1. Update `package.json` > `dependencies` with `@ngrx/store`.
2. Run `npm install` to install those dependencies.
2. Run `npm install` to install those dependencies.
3. Update your `src/app/app.module.ts` > `imports` array with `StoreModule.forRoot({})`.

```sh
ng add @ngrx/store --minimal false
```

This command will automate the following steps:

1. Update `package.json` > `dependencies` with `@ngrx/store`.
2. Run `npm install` to install those dependencies.
3. Create a `src/app/reducers` folder, unless the `statePath` flag is provided, in which case this would be created based on the flag.
4. Create a `src/app/reducers/index.ts` file with an empty `State` interface, an empty `reducers` map, and an empty `metaReducers` array. This may be created under a different directory if the `statePath` flag is provided.
5. Update your `src/app/app.module.ts` > `imports` array with `StoreModule.forRoot(reducers, { metaReducers })`. If you provided flags then the command will attempt to locate and update module found by the flags.

0 comments on commit 7ecaa22

Please sign in to comment.