0
votes
  • Angular 10
  • ngrx/store: 9.2.0

Hello, I have an app including multiple store, let give you an instance, I have User and Roles, each user belong to a Role and each role has its own properties,

  • User (id, fullname, role_id, status, ...)
  • Role (id, name, resources, etc...)

I have fully NGRX setup for Role, CRUD operation are working fine, now it's time to start setup the store for User too, but User module is a bit different, for example in the data table of user I want to show the role's name and resources, now the question here is:

  1. Shall I create special model for User, which is contains user columns as well as to extra cols role name and resources, or should I get the role info from server using user effect by passing role id to role service and update the state with role information ? if so would you please give me a hint ?

  2. in NGRX the model should be as it is and the within the other components I can get the information of another store, for example User model as it is and doing it's own CRUD , as well as Role , and the in User data table component when I fetched the user info, pass the role id to Role action to get the role info? does the architecture should be like this or what ?

I am using lazy loading , and each module is inside it's own folder :

modules:
- user
-- components
-- store
--- user.model.ts
--- user.actions.ts
--- user.effects.ts
--- user.reducer.ts
--- user.selectors.ts
- user.module.ts
- user-routing.module.ts

- Role
-- components
-- store
--- role.model.ts
--- role.actions.ts
--- role.effects.ts
--- role.reducer.ts
--- role.selectors.ts
- role.module.ts
- role-routing.module.ts
1

1 Answers

1
votes

Your store setup is fine in my eyes. If you want to connect multiple slices of the store, selectors are the way to go. See my blog post Sharing data between modules is peanuts for more info and an example.