Warning from ngrx about runtime checks

[亡魂溺海] 提交于 2019-12-30 17:19:32

问题


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:


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.



来源:https://stackoverflow.com/questions/57127658/warning-from-ngrx-about-runtime-checks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!