ngrx关于运行时检查的警告

fr0*_*fr0 10 ngrx angular ngrx-store

我使用将我的应用程序从Angular 7升级到Angular 8 ng update。当我通过运行它时ng serve,控制台上印有一个警告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.
Run Code Online (Sandbox Code Playgroud)

提供的链接上的文档讨论了ngrx-store-freeze不推荐使用的内容。但是,我的应用程序未使用ngrx-store-freeze,我也不知道什么是“运行时检查”。我需要在代码中进行哪些更改以解决此警告的来源?

use*_*584 21

出现此警告的原因是,在NGRX <8中,要使存储不可变,我们需要使用ngrx-store-freeze库。在NGRX 8中,您可以选择不使用ngrx-store-freeze而使存储不可变(因为它现在在NGRX 8中是内置的)。如果您通过指定runtimeChecks属性来选择店内不变性,则该警告将消失StoreModule.forRoot:

StoreModule.forRoot(rootReducer, {
      runtimeChecks: {
        strictStateImmutability: true,
        strictActionImmutability: true
      }      
    })
Run Code Online (Sandbox Code Playgroud)

例:

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

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

希望这可以帮助。