这是我的效果:
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
,如何实现这一点?
尝试此方法 - 在处理 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 实例注入到您的组件或服务中。