NGRX存储adapter.updateone不会更改属性以进行更改检测

时间:2019-02-06 16:43:08

标签: angular ngrx

我有以下减速器:

case ProductionCommentActionTypes.EditCommentSuccess: {
  return adapter.updateOne(action.payload, state);
}

其中有效载荷是以下对象:

{ 
    id: number,
    changes: { 
       id: number;
       avatar: string;
       createdAt: Date;
       createdBy: string;
       body: string;
       discipline: string;
       isConcern: boolean;
       isResolved: boolean;
       plan_Id: number;
       resolution: {
                    id: number;
                    comment_Id: number;
                    avatar: string;
                    createdAt: Date;
                    createdBy: string;
                    body: string;   
                   }
      }
}

不幸的是,当我去更新对象时,我可以清楚地看到action.payload确实有数据正在被删除。我已经检查了action.payload和效果:

  @Effect()
  resolveProductionConcernSuccess$: Observable<Action> = this.actions$
  .ofType<ResolveConcernSuccess>(ProductionCommentActionTypes.ResolveConcernSuccess).pipe(
    // Performing a get rather than an edit as the comment should have already 
    // been updated in the service when the resolution was added.
    switchMap(action => this.commentService.getComment(action.payload.comment_Id)), 
          map((comment: any) => {
            comment.updatedBy = "test";
        return new EditCommentSuccess(comment);
      }),
    catchError(err => of(new EditCommentFail(err)))
  );

但是,我从中看到的是

  this.comments$ = rootStore.select<Comment[]>(fromRoot.getCommentsForSelectedPlan);
this.comments$.subscribe(res => console.log(res));

是旧数据,即使触发了更改。我至少应该期望看到updateBy =“ test”。如果我在调试器中逐步执行,我还将在updateOne之后立即在状态 上看到旧数据。

另一种说法是

      return adapter.updateOne(action.payload, state);

尽管有效负载中的值正确,但似乎并没有真正改变任何东西。

为什么状态上的属性实际上未更新?有合适的方法吗?

1 个答案:

答案 0 :(得分:0)

问题出在减速器上。

返回adapter.updateOne({id:action.payload.id,更改:action.payload},状态);