Search code examples
angularngrxreducersspartacus-storefront

Spartacus Loader Meta Reducer - Product Search


I am trying to incorporate a loading spinner when loading and navigating between the PLP pages.

I see in the documentation that this behavior is facilitated by loaderReducer, but the main drawback I have is that I do not have access to the product reducers.

I can create a custom actions extending the StateUtils.EntityLoadAction and getting the loading boolean in the store but whith the custom reducer for product > search I lose the reducer for:

  • product > details
  • product > reviews
  • product > references

Since I don't have access to them and im replacing the reducer for PRODUCT_FEATURE = 'product'

Screenshot Product Reducer Spartacus 2.1.x

  1. Reducer that I want and can replace
  2. The reducers that I lose

Does anyone know a work around ?

Spartacus version: 2.1.x


Solution

  • generally it's not trivial to extend ngrx reducer and state, as it basically requires to create new reducer, state shape, selecors, actions and use them in custmosed facades. I would not go this route.

    For you specific case I would consider exposing loading flag just by observing ProductSearchActions, like SearchProducts, SearchProductsSuccess, SearchProductsFail. It looks like much more simpler approach that should give you exactly the same information without the overhead of extending the store.