title: Redux - Why normalize?
body: <p>I have been trying to learn how to better structure my Redux stores and stumbled upon this lesson by Dan.</p>
  
  <p><a href="https://egghead.io/lessons/javascript-redux-normalizing-the-state-shape#/guidelinesModal" rel="noreferrer">https://egghead.io/lessons/javascript-redux-normalizing-the-state-shape#/guidelinesModal</a></p>
  
  <p>Although I understand how to go about normalizing my data in this way, I do not understand the motivation behind it. Particularly, I have two questions.</p>
  
  <ol>
  <li><p>Why wont simple arrays be sufficient? Dan mentions - "In complex apps, we might have more than a single array and todos with the same IDs in different arrays might get out of sync". I did not understand this, may I have an example? The only benefit I see from using an object is improved efficiency as we do not need to map over the entire array, in case I want to delegate a certain todo to another reducer.</p></li>
  <li><p>Why do we need to maintain a list of allIds? Why maintain this additional state, when we can easily map over the list of all todos and obtain it?</p></li>
  </ol>
  
  <p>I know that normalizr does this for us, but why should we normalize in the first place? Does it make sense to normalize even if the responses are not deeply nested? </p>
  
  <p><strong>Edit 1:</strong></p>
  
  <p>Thanks for your answer, Christopher.</p>
  
  <p>Let us assume that your state tree looks like this</p>
  
  <pre><code>{
      user: {
          byId: {
              1: {
                  id: 1,
                  name: 'Buy stuff'
                 }, 
              2: {
                  id: 2,
                  name: 'Yeah'
                 }
              }
          },
          allIds: [1, 2],
          subscribedIds: [5],
      }
      department: {
          byId: {
              5: {
                  id: 5,
                  name: 'Sell Stuff'
              }
          },
          allIds: [5],
          subscribedIds: []
      }   
  }
  </code></pre>
  
  <p>I do not see the benefit of having an object in place of an array here. I could as well have selectors which would fetch the subscribed todo by ID from departments, even if it is an array. It seems my understanding of the concept is a bit deficient. Could you please elaborate?</p>