Warning from ngrx about runtime checks

2020-03-09 05:27发布

I upgraded my app from Angular 7 to Angular 8 using ng update. When I run it via ng serve, There's a warning printed in my console from ngrx:

@ngrx/store: runtime checks are currently opt-in but will be the default in the next major version with the possibility to opt-out, see https://ngrx.io/guide/migration/v8 for more information.

The documentation at the provided link talks about ngrx-store-freeze being deprecated. However, my application does not use ngrx-store-freeze, and I have no idea what a "runtime check" is. What do I need to change in my code to address the source of this warning?

1条回答
该账号已被封号
2楼-- · 2020-03-09 05:45

This warning is coming because in NGRX < 8, to make store immutable, we need to use ngrx-store-freeze library. In NGRX 8, you can opt-in to make store immutable without ngrx-store-freeze [as it is in build now in NGRX 8]. This warning will go away if you opt in-store immutability by specifying runtimeChecks property in StoreModule.forRoot like this:

StoreModule.forRoot(rootReducer, {
      runtimeChecks: {
        strictStateImmutability: true,
        strictActionImmutability: true
      }      
    })

Example:

@NgModule({
  imports: [
    CommonModule,
    StoreModule.forRoot(rootReducer, {
      runtimeChecks: {
        strictStateImmutability: true,
        strictActionImmutability: true
      }      
    }),
  ]
})
export class AppModule {}

Ref: https://medium.com/ngrx/announcing-ngrx-version-8-ngrx-data-create-functions-runtime-checks-and-mock-selectors-a44fac112627

Hope this helps.

查看更多
登录 后发表回答