Skip to content

Commit

Permalink
Change the place where to spread the object
Browse files Browse the repository at this point in the history
  • Loading branch information
OtterleyW committed May 8, 2019
1 parent a21e1ad commit c8c0dc3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/util/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const combinedResourceObjects = (oldRes, newRes) => {
throw new Error('Cannot merge resource objects with different ids or types');
}
const attributes = newRes.attributes || oldRes.attributes;
const attrs = attributes ? { attributes } : null;
const attrs = attributes ? { attributes: { ...attributes } } : null;
const relationships = combinedRelationships(oldRes.relationships, newRes.relationships);
const rels = relationships ? { relationships } : null;
return { id, type, ...attrs, ...rels };
Expand All @@ -40,7 +40,6 @@ export const combinedResourceObjects = (oldRes, newRes) => {
export const updatedEntities = (oldEntities, apiResponse) => {
const { data, included = [] } = apiResponse;
const objects = (Array.isArray(data) ? data : [data]).concat(included);
const originalEntities = { ...oldEntities };

const newEntities = objects.reduce((entities, curr) => {
const { id, type } = curr;
Expand All @@ -51,9 +50,10 @@ export const updatedEntities = (oldEntities, apiResponse) => {

entities[type] = entities[type] || {};
const entity = entities[type][id.uuid];
entities[type][id.uuid] = entity ? combinedResourceObjects(entity, current) : current;
entities[type][id.uuid] = entity ? combinedResourceObjects({ ...entity }, current) : current;

return entities;
}, originalEntities);
}, oldEntities);

return newEntities;
};
Expand Down

0 comments on commit c8c0dc3

Please sign in to comment.