I am struggling to utilize a selector with props (of type MemoizedSelectorWithProps) in an effect inside WithLatestFrom. The issue arises because the parameter for the selector (the props) is derived from the action payload, making it difficult for withLatestFrom to access the action payload.
My current setup involves Angular 7 and ngrx7. I have attempted using a map to create a new observable without much success...
To better illustrate my predicament, here are some simplified code snippets:
Action:
export const GET_INVENTORY = '[App] Get Inventory';
export class GetInventory implements Action {
readonly type = GET_INVENTORY;
constructor(public branchId: number) {}
}
Effect:
@Effect()
getInventory$ = this.actions$.pipe(
ofType(GET_INVENTORY),
withLatestFrom(this.store$.pipe(select(getIsStoreInventoryLoaded, {branchId: action.branchId}))), // Unable to access 'action' here
switchMap([action, loaded]: [GetInventory, boolean] => {
if (loaded) {
console.log('already loaded inventory for this branch', action.branchId);
} else {
console.log('never loaded inventory for this branch', action.branchId);
}
});
While this represents a simplified version of my scenario, the fundamental concept mirrors what I am dealing with in my actual project - maintaining inventory data per "branch" within the store. As a chain of supermarkets, each branch has its own specific inventory data page, where re-fetching should be avoided if already loaded. If you have alternative suggestions other than utilizing MemoizedSelectorWithProps, I am open to exploring those as well.