来自 ngrx 的关于运行时检查的警告

Warning from ngrx about runtime checks

我使用 ng update 将我的应用程序从 Angular 7 升级到 Angular 8。当我通过 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.

提供的 link 中的文档讨论了 ngrx-store-freeze 被弃用的问题。但是,我的应用程序不使用 ngrx-store-freeze,而且我不知道 "runtime check" 是什么。我需要更改代码中的哪些内容才能解决此警告的来源?

出现此警告是因为在 NGRX < 8 中,要使存储不可变,我们需要使用 ngrx-store-freeze 库。在 NGRX 8 中,您可以 opt-in 使存储不可变而无需 ngrx-store-freeze [因为它现在在 NGRX 8 中构建]。如果您通过在 StoreModule.forRoot 中指定 runtimeChecks 属性 来选择 in-store 不变性,则此警告将消失:

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

示例:

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

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

希望这对您有所帮助。