【问题标题】:Warning from ngrx about runtime checks来自 ngrx 的关于运行时检查的警告
【发布时间】:2019-11-29 08:17:44
【问题描述】:

我使用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.

所提供链接中的文档谈到 ngrx-store-freeze 已被弃用。但是,我的应用程序没有使用ngrx-store-freeze,而且我不知道什么是“运行时检查”。我需要对代码进行哪些更改才能解决此警告的来源?

【问题讨论】:

  • packagej.json 文件中引用了哪个版本的ngrx?

标签: angular ngrx ngrx-store


【解决方案1】:

这个警告出现是因为在 NGRX StoreModule.forRoot 中指定 runtimeChecks 属性来选择店内不变性,则此警告将消失,如下所示:

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

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    • 2017-12-17
    相关资源
    最近更新 更多