On Monday, the team behind NgRx, a platform that provides reactive libraries for Angular, announced the release of NgRx 8. This release includes the NgRx Data package, creator functions, four run-time checks, mock selectors, and much more.
Following are some of the updates in NgRx 8:
NgRx Data integrated into the NgRx platform
In this release, the team has integrated the angular-ngrx-data library by John Papa and Ward Bell directly into the NgRx platform as a first-party package. Using NgRx in your Angular applications properly requires a deeper understanding and a lot of boilerplate code. This package gives you a “gentle introduction” to NgRx without the boilerplate code and simplifies entity data management.
Redesigned creator functions
NgRx 8 comes with two new creator functions:
- createAction: Previously, while creating an action you had to create an action type, create a class, and lastly, create an action union. The new createAction function allows you to create actions in a less verbose way.
- createReducer: With this function, you will be able to create a reducer without a switch statement. It takes the initial state as the first parameter and any number of ‘on’ functions.
Four new runtime checks
To help developers better follow the NgRx core concepts and best practices, this release comes with four runtime checks. These are introduced to “shorten the feedback loop of easy-to-make mistakes when you’re starting to use NgRx, or even a well-seasoned developer might make.”
The four runtime checks that have been added are:
- The strictStateImmutability check verifies whether a developer is trying to modify the state object.
- The strictActionImmutability check verifies that actions are not modified.
- The strictStateSerializability check verifies if the state is serializable.
- The strictActionSerializability check verifies if the action is serializable.
All of these checks are opt-in and will be disabled automatically in production builds.
Mock selectors for isolated unit testing
NgRx 7 came with MockStore, a simpler way to condition NgRx state in unit tests. But, it does not allow isolated unit testing on its own. NgRx 8 combines mock selectors and MockStore to make this possible. You can use these mock selectors by importing @ngrx/store/testing.
To know more in detail, check out the official announcement on Medium.