I am trying to merge an immutable array of objects using Reacts Immutability helpers or Immutable js which ever one. I am trying to create a list of only records where the names have changed. I am trying to avoid creating duplicates in the list if the name has been changed multiple times before submission which lead me to believe a merge was the path I needed to take. An example of what I am trying to achieve is below.
var objArray = [{id:4, name:'bar'}, {id:10, name:'test'}];
var newObj = {id:4, name:'foo'};
var updatedEntries = update(this.state.nameChanges, {$merge: {newObj});
The Result I am looking for is:
objArray = [{id:4, name:'foo'}, {id:10, name:'test'}]
The Result I seem to be getting is:
objArray = [{id:4, name:'foo'}]
I have tried using Facebook React immutability helpers but cannot seem to get the result I need. I seem to be having a little trouble trying wrapping my head around what the merge function is actually doing. Any help is appreciated.
Thanks
updatedoes, butmergeworks for me