Aller au contenu principal

NgRx update

See V9 Update Guide for more details.

Creators syntax

v8 introduced a less verbose syntax following a Good Action Hygiene. It is used by default in v9 (all schematics).

See NgRx: Action Creators redesigned & NgRx creator functions 101 for more details.

createAction

example

new createAction factory function vs old Action interface

createReducer

example

Avoid switch statement ➕ no need for a default case.

new createReducer factory function vs old syntax

createEffect

example

Type safe (i.e. if the effect does not return an Observable\<Action> it will give compile errors).

new createEffact factory function vs old syntax

Runtime checks

4 runtime checks where introduced in v8 (replacing the ngrx-store-freeze package):

  • strictStateImmutability: to verify that the state isn’t mutated
  • strictActionImmutability: to verify that actions aren’t mutated
  • strictStateSerializability: to verify if the state is serializable
  • strictActionSerializability: to verify if the actions are serializable

v9 enabled strictStateImmutability and strictActionImmutability by default in development and added strictActionWithinNgZone.

@NgModule({
imports: [
StoreModule.forRoot(reducers, {
runtimeChecks: {
// strictStateImmutability: true,
// strictActionImmutability: true,
strictStateSerializability: true,
strictActionSerializability: true,
strictActionWithinNgZone: true,
},
}),
],
})
export class AppModule {}

Deprecrations

  • v9: @nrgx/entity addAll ➡️ setAll