Is it okay for ngrx dat…

less than 1 minute read

Is it okay for ngrx data-access libraries to depend on each other? Say you have an CartItems feature state. This keeps track of all items in your cart. Now, since its scope spans beyond just one page on your app, you should be able to call AddItemToCart(payload) from a “search page”, “my cart”, and more. If we keep a generic [Cart] Add item to cart action all is good. The smart components for each page can simply import the exported action from the data-access library.

However, this doesn’t follow good action hygiene:

^TL;DR actions should be events and specific to where they came from. So our [Cart] Add item to cart becomes [Search Page] Add item to cart and [Search Page] Add item to cart.

The only way I can see this working is by creating data-access libraries for each feature/page that may have no module and only a +state/state.actions.ts. These actions will now be imported into the data-access-cart module and added to reducers and effects. Is this still considered okay? Thanks!