3

I am currently working on an ngrx store project using ngrx entites in which I would like to compose some selectors, like this:

export const selectProductById = (productId: number) => createSelector(
  selectProductState,
  productsState => productsState.entities[productId]
);

export const selectCurrentProduct = createSelector(
  selectProductState,
  productsState => productsState.entities[productsState.selectedProductId]
);

I would like to use the selectProductById selector in the selectCurrentProduct selector, like this:

// doesn't work
export const selectCurrentProduct = createSelector(
  selectProductState,
  productsState => selectProductById(productsState.selectedProductId)
);

What would be the syntax? This causes compilation errors where I try to use the selectCurrentProduct selector:

Type 'Observable<emoizedSelector<object, Product>>' is not assignable to type 'Observable<Product>'

Update

Thanks for all the links and stuff, but they don't really address my problem. I am looking to create a selector using createSelector() using another selector, also created by createSelector(). Please see my pseudocode above. I am trying to use te selectProductById using the selectProductById selector.

serlingpa
  • 12,024
  • 24
  • 80
  • 130
  • 1
    This might help you with some ideas around parameterized selectors: https://stackoverflow.com/questions/53546085/ngrx-how-to-pass-parameters-to-selector-inside-createselector-method/53546233#53546233, if that is what you are looking for. – R. Richards Feb 28 '19 at 17:38
  • Possible duplicate of [ngrx: how to pass parameters to selector inside createSelector method](https://stackoverflow.com/questions/53546085/ngrx-how-to-pass-parameters-to-selector-inside-createselector-method) – timdeschryver Feb 28 '19 at 19:33

0 Answers0