title: Pass by reference assignment mutates redux state
body: <p>I have an app with a menu of items, and at some point a user may edit the values of the items. When the user does so, I create a copy of the item in a seperate state branch instead of changing the original menu items. So my reducer looks like this:</p>
  
  <pre><code>const menuReducer = (state = [], action) =&gt; {
    switch (action.type) {
      case ADD_ITEM:
        return [...state, {id: action.itemId, propA: action.itemPropA, propB: action.itemPropB}]
    }
  }
  
  const editingMenuItem = (state = {}, action) =&gt; {
    switch (action.type) {
      case SET_EDIT_ITEM:
        return {id: action.id, propA: action.itemPropA, propB: action.itemPropB}
      case EDIT_ITEM:
        return {id: state.id, propA: action.itemPropA, propB: action.itemPropB}
    }
  }
  </code></pre>
  
  <p>Someone selects that they want to edit an item, and this causes the <code>dispatchEditItem</code> thunk to trigger and create a copy in the state tree:</p>
  
  <pre><code>const dispatchEditItemThunk = itemId =&gt; (dispatch, getState) =&gt; {
    const item = _.find(getState().menu, ['id', itemId]);
    dispatch(setEditItem(item.id, item.propA, item.propB))
  }
  </code></pre>
  
  <p>Then when someone wants to edit a prop, the <code>editingThunk</code> is dispatched:</p>
  
  <pre><code>const editingThunk = (itemId, propName) =&gt; (dispatch, getState) =&gt; {
    let activeItem = getState().editingMenuItem;
    // someValue is generated here
    activeItem[propName] = someValue
    dispatch(editItem(activeItem.propA, activeItem.propB))
  }
  </code></pre>
  
  <p>The problem with this is that when <code>activeItem[propName] = someValue</code> happens, this <em>changes the value of the item contained in the menuReducer array.</em> I'm assuming because everything is pass by reference, and all the references lead back to the original value in the menuReducer. However, this isn't the way I would expect this to work. My assumption would be that calling <code>getState</code> would return a deep copy of the state, and not allow for these kinds of accidental mutations.</p>
  
  <p>Is this a bug? If it isn't, is there a preferred way of writing thunks that avoids this kind of situation? In my real use case, the structure of the props in the menuItem is very complex, and it is handy to create an <code>activeItem</code> in the thunk and mutate it's values before dispatching to the state tree. Is doing this bad? </p>