Search code examples
angularngrx

use ngrx effect for api request but dont store result in store


I am working on an Angular project which is using ngrx/store.

A component of mine needs data from the backend. So the flow usually is like this:

  1. dispatch Action
  2. invoke Effect --> call backend
  3. update store with data from backend
  4. component uses selector to get the data

Now we have the case that our backend returns lots of data (e.g. 100.000) entries. For some reasons I can not do pagination.

I am currently thinking to NOT keep the 100.000 entries in the store since the data is not used anywhere else in the app (SHARI principle violated). Would you think this is a good idea:

  1. dispatch Action
  2. invoke Effect --> call backend
  3. component listens for ApiCallSuccess Action and uses data from payload.

The benefit from my side would be: We always use Effects to call the backend (consistency).

What would you suggest? The alternative to me is that the component just calls the API and uses data directly.


Solution

  • Both options have pros and cons - and I think that it's your choice and your teams choice.

    You can also take a look @ngrx/component-store which is a middle ground, and a good fit for state that is bound to the component's lifestyle.