title: Ngrx store manage multiple lists of objects
body: <p>I'm developing Angular 2 application together with <code>ngrx</code>. I have several questions of how implement store based on my current project requirements.</p>
  <p>To be more specific let's say I have two list of users on my website. The first list contains <code>Active users</code> and another list contains the <code>Best contributors</code>. All objects inside both list are type of <code>User</code> which is defined by:</p>
  <pre><code>export interface User {
      id: string
      firstName: string,
      lastName, string
      email: string
  }
  </code></pre>
  <p>There are several ways to implement these two lists inside the store. I have 3 possible ways to do it, but I would like to hear how are other people doing it.</p>
  <h1>Approach 1</h1>
  <p>In this case every angular component, in this case <code>Active users</code> and <code>Top contributors</code> will have its own object inside the store, together with belonging reducers, effects etc.</p>
  <pre><code>activeUsers: [
      {
          id: 1
          firstName: &quot;User 1&quot;
          lastName: &quot;Lastname 1&quot;
          email: &quot;user1@example.com&quot;
      },
      {
          id: 2
          firstName: &quot;User 2&quot;
          lastName: &quot;Lastname 2&quot;
          email: &quot;user2@example.com&quot;
      },
  
  ]
  
  
   topContributors: [
      {
          id: 1
          firstName: &quot;User 1&quot;
          lastName: &quot;Lastname 1&quot;
          email: &quot;user1@example.com&quot;
      },
      {
          id: 5
          firstName: &quot;User 5&quot;
          lastName: &quot;Lastname 5&quot;
          email: &quot;user5@example.com&quot;
      },
  
  ]   
  </code></pre>
  <p>Having separated store objects for separated lists will give me a benefit to have really simple reducers so I can easily add/remove/update data, but there is now another problem. For example <code>User 1</code> is in both lists and I have to update this object on two places which is adding really similar logic on 2 places. Ideally would be to have one reducer that can handle both lists which leads me to approach 2.</p>
  <h1>Approach 2</h1>
  <p>In this case store will contain top <code>user</code> object which then contains array of users separated by list name. Here is an example:</p>
  <pre><code>users: [
      activeUsers: [
      {
          id: 1
          firstName: &quot;User 1&quot;
          lastName: &quot;Lastname 1&quot;
          email: &quot;user1@example.com&quot;
      },
      {
          id: 2
          firstName: &quot;User 2&quot;
          lastName: &quot;Lastname 2&quot;
          email: &quot;user2@example.com&quot;
      },
  
  ]
  
  
   topContributors: [
      {
          id: 1
          firstName: &quot;User 1&quot;
          lastName: &quot;Lastname 1&quot;
          email: &quot;user1@example.com&quot;
      },
      {
          id: 5
          firstName: &quot;User 5&quot;
          lastName: &quot;Lastname 5&quot;
          email: &quot;user5@example.com&quot;
      },
  
      ]   
  ]
  </code></pre>
  <p>In this case, reducers will be a bit more complex (because they have to handle specific list based on the list name), but enough general to add/remove/update any list I have. Again, in this case, I have to go through all lists and find user I want to let's say edit and edit it multiple times. Please note that in this case every list has to be uniquely identified by name like in my case: <code>activeUsers</code>, <code>topContributors</code>. This gives me great ability to create selectors that will return me desired list:</p>
  <pre><code>this.store.select(userList(&quot;activeUsers&quot;)).subscribe()
  </code></pre>
  <p>Things could be more complex if we start adding more nested data, but I will try to avoid that.</p>
  <h1>Approach 3</h1>
  <p>Redux pattern is suggesting to have so called tables in the store. That means I will have a table called users where I will store all user objects. Let's say I have two API calls. One will fetch active users and another api call will fetch top contributors. At which moment I have to merge these two sources so I have table of users in the store with no duplicated entry (for example user 1 can be in both lists)?</p>
  <h1>Question</h1>
  <p>How do you handle store (how you design it) when you manage multiple lists of the same objects on your website?</p>