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.
8.0.0-beta.0 (2019-04-17)
Bug Fixes
- effects: add the export of EffectMetadata (#1720) (214316f)
- example: handle possible undefined results from Dictionary (#1745) (861b0cb), closes #1735
- schematics: check for empty name when using store schematic for feature states (#1659) (#1666) (3b9b890)
- store: add the missing bracket in immutability meta-reducer (#1721) (56f8a59)
- Store: selector with only a projector (#1579) (da1ec80), closes #1558
- StoreDevTools: rename action list filters (#1589) (5581826), closes #1557
Code Refactoring
Features
BREAKING CHANGES
- entity: Dictionary could be producing undefined but previous typings were not explicit about it.
- Store: Internal functions and tokens are removed from the public API
- router-store: usage of forRoot is now required for StoreRouterConnectingModule
BEFORE:
@NgModule({
imports: [StoreRouterConnectingModule],
})
export class AppModule {}
AFTER:
@NgModule({
imports: [StoreRouterConnectingModule.forRoot()],
})
export class AppModule {}
- Store: Selectors with only a projector function aren't valid anymore.
This change will make the usage more consistent.
BEFORE:
const getTodosById = createSelector((state: TodoAppSchema, id: number) => state.todos.find((p) => p.id === id));
AFTER:
const getTodosById = createSelector(
(state: TodoAppSchema) => state.todos,
(todos: Todo[], id: number) => todos.find((p) => p.id === id)
);
- StoreDevTools:
actionsWhitelist
is renamed to actionsSafelist
actionsBlacklist
is renamed to actionsBlocklist
BEFORE:
StoreDevtoolsModule.instrument({
actionsWhitelist: ['...'],
actionsBlacklist: ['...'],
});
AFTER:
StoreDevtoolsModule.instrument({
actionsSafelist: ['...'],
actionsBlocklist: ['...'],
});
<a name="7.4.0"></a>