NGRX 状态突变

问题描述

我正在使用 Angular CLI 和 NGRX 版本 10 开发一个企业 Angular 项目。 在组件内部,我通过选择器接收状态属性,然后更改该对象。我没有收到任何错误,这让我感到困惑,因为状态是不可变的,但它被静音而没有任何错误。

解决方法

默认情况下,ngrx 不会检测此类错误以提高性能。

如果您愿意,可以在本地开发期间启用它们:

@NgModule({
  imports: [
    StoreModule.forRoot(reducers,{
      runtimeChecks: {
        strictStateImmutability: true,// <- what you need
        strictActionImmutability: true,// <- what you need
        strictStateSerializability: true,strictActionSerializability: true,strictActionWithinNgZone: true,strictActionTypeUniqueness: true,},}),],})
export class AppModule {}

更多信息在这里:https://ngrx.io/guide/store/configuration/runtime-checks

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...