ngrx:如何在效果之前和之后调用减速器

问题描述 投票:0回答:1

我想修复以下警告:

ESLint: Calling 'store.dispatch' in 'Effect' is forbidden.

所讨论的效果通常是这样的:

  • 使用reducer锁定存储中的数据
  • 更新后台数据
  • 解锁数据

代码:

    this.actions$.pipe(
              ofType(actions.update),
              switchMap(action => {
                this.store.dispatch(actions.lockData(action.data.id));
                return this.backendService.update$(action.data)
                 .pipe(
                    map(...),
                    catchError(...),
                    finalize(()=> this.store.dispatch(actions.unlockData(action.data.id))  
                    )

如何正确做?

typescript ngrx ngrx-effects
1个回答
0
投票

您可以使用触发效果的操作以及从效果返回的操作来锁定/解锁数据。

在您的情况下,这意味着

actions.update
,并且操作在
map
方法中返回。

© www.soinside.com 2019 - 2024. All rights reserved.