在角度效果中调用load之前如何重置

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

这是我的效果:

 loadProductCategoryWise$ = createEffect(() =>
    this.actions$.pipe(
      ofType(productInventoryAction.loadProductCategoryWise),
      mergeMap((action) =>
        this.stockApi.getProductCategoryWise(action.rid, action.version, action.cat_id).pipe(
          map((data: any) => {

            if(data.statusCode === 200){

              return productInventoryAction.loadProductCategoryWiseSuccess({ data: data.data  })

            }
            else{
              return productInventoryAction.loadProductCategoryWiseFail({ error: data })
            }
          }),//, total: data.totall
          catchError((error: any) => of(productInventoryAction.loadProductCategoryWiseFail({ error })))
        )
      )
    )
  );

我需要在调用

productInventoryAction.resetStore
之前先调用
loadProductCategoryWise
,如何实现这一点?

angular store reset ngrx-effects
1个回答
0
投票

尝试此方法 - 在处理 loadProductCategoryWise 操作之前使用 tap 运算符分派 resetStore 操作

loadProductCategoryWise$ = createEffect(() =>
this.actions$.pipe(
ofType(productInventoryAction.loadProductCategoryWise),
tap(() => this.store.dispatch(productInventoryAction.resetStore())),
mergeMap((action) =>
  this.stockApi.getProductCategoryWise(action.rid, action.version, action.cat_id).pipe(
    map((data: any) => {
      if (data.statusCode === 200) {
        return productInventoryAction.loadProductCategoryWiseSuccess({ data: data.data });
      } else {
        return productInventoryAction.loadProductCategoryWiseFail({ error: 
data });
      }
    }),
    catchError((error: any) => 
      of(productInventoryAction.loadProductCategoryWiseFail({ error })))
     )
    )
  )
);

注意-我们使用存储来调度resetStore操作。确保您已将 Store 实例注入到您的组件或服务中。

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