What is @ngrx/schematics?
@ngrx/schematics is a collection of Angular schematics for generating NgRx files such as actions, reducers, effects, and more. It helps streamline the process of setting up and maintaining NgRx in Angular applications.
What are @ngrx/schematics's main functionalities?
Generate Store
This command generates a new NgRx store with the specified state and sets it up in the root module. It creates necessary files and boilerplate code for the store.
ng generate @ngrx/schematics:store State --root --module app.module.ts
Generate Actions
This command generates a new set of actions for a specified feature (e.g., User). It creates an actions file with predefined action types and classes.
ng generate @ngrx/schematics:action User
Generate Reducer
This command generates a new reducer for a specified feature (e.g., User). It creates a reducer file with initial state, reducer function, and necessary imports.
ng generate @ngrx/schematics:reducer User
Generate Effects
This command generates a new effect for a specified feature (e.g., User). It creates an effects file with boilerplate code for handling side effects in NgRx.
ng generate @ngrx/schematics:effect User
Other packages similar to @ngrx/schematics
@angular/cli
@angular/cli is the official Angular CLI tool that provides a wide range of commands for generating and managing Angular projects. While it does not specifically focus on NgRx, it can be extended with custom schematics to include NgRx-related functionality.
nx
Nx is a set of extensible dev tools for monorepos, which helps you develop like Google, Facebook, and Microsoft. It provides powerful CLI commands for generating and managing Angular applications, including support for NgRx. Nx offers more advanced features for managing large-scale projects compared to @ngrx/schematics.
schematics-utilities
schematics-utilities is a utility library for Angular schematics that provides helper functions for creating and modifying Angular projects. It can be used to create custom schematics, including those for NgRx, but requires more manual setup compared to @ngrx/schematics.
15.0.0-rc.0 (2022-11-23)
Features
- component: clear
LetDirective
view when replaced observable is in suspense state (#3671) (ec59c4b) - component: remove $ prefix from LetViewContext property names (#3670) (b3b21e6)
BREAKING CHANGES
- component: The
LetDirective
view will be cleared when the replaced observable is in a suspense state. Also, the suspense
property is removed from the LetViewContext
because it would always be false
when the LetDirective
view is rendered. Instead of suspense
property, use the suspense template to handle the suspense state.
BEFORE:
The LetDirective
view will not be cleared when the replaced observable is in a suspense state and the suspense template is not passed:
@Component({
template: `
<!-- When button is clicked, the 'LetDirective' view won't be cleared. -->
<!-- Instead, the value of 'o' will be 'undefined' until the replaced -->
<!-- observable emits the first value (after 1 second). -->
<p *ngrxLet="obs$ as o">{{ o }}</p>
<button (click)="replaceObs()">Replace Observable</button>
`,
})
export class TestComponent {
obs$ = of(1);
replaceObs(): void {
this.obs$ = of(2).pipe(delay(1000));
}
}
AFTER:
The LetDirective
view will be cleared when the replaced observable is in a suspense state and the suspense template is not passed:
@Component({
template: `
<!-- When button is clicked, the 'LetDirective' view will be cleared. -->
<!-- The view will be created again when the replaced observable -->
<!-- emits the first value (after 1 second). -->
<p *ngrxLet="obs$ as o">{{ o }}</p>
<button (click)="replaceObs()">Replace Observable</button>
`,
})
export class TestComponent {
obs$ = of(1);
replaceObs(): void {
this.obs$ = of(2).pipe(delay(1000));
}
}
- component: The
$
prefix is removed from LetViewContext
property names.
BEFORE:
<ng-container *ngrxLet="obs$; $error as e; $complete as c"> ... </ng-container>
AFTER:
<ng-container *ngrxLet="obs$; error as e; complete as c"> ... </ng-container>
<a name="15.0.0-beta.1"></a>