我正面临一个我无法解决的有线问题
实际上我有以下内容:
getProduct$ = createEffect(() =>
this.actions$.pipe(
ofType(ACTIONS.getProduct),
mergeMap(({ id }) =>
this.shopService.getProduct(id).pipe(
tap(p => console.log('product from store', p)),
map((response) => ACTIONS.getProductSuccessResponse(response)),
catchError((err) => of(ACTIONS.getProductErrorResponse(err)))
)
)
)
)
在组件中我这样做了:
ngOnInit(): void {
const productId = +this.route.snapshot.params['id']
this.store$.dispatch(actions.getProduct({ id: productId }))
this.product$ = this.actions$.pipe(
ofType(actions.getProductSuccessResponse),
tap(p => console.log('product from cmp', p))
)
this.actions$.pipe(
ofType(actions.getProductErrorResponse),
tap(({ message }) =>
this.notificationService.notifyAtBottomMiddle({
detail: message,
severity: 'error',
})
)
)
}
并在服务中获取产品:
public getProduct(id: number, useCache = USE_CACHE): Observable<IProduct> {
if (useCache && this.productsQueryCache.size) {
const product = this.getProductFromCache(id)
if (product) return of(product)
}
return this.httpService.get<IProduct>(`${baseUrl}/products/${id}`)
}
问题是我总是从商店获取log但不是从组件获取,我不明白为什么会这样。
现在,如果我刷新页面(不使用缓存)它工作正常 但我不明白为什么缓存没有
缓存 100% 有效,我 总是从产品商店获取 console.log ! 任何帮助plzz 也许它在我不知道的组件中www helppp