Skip to content

Commit

Permalink
Merge pull request #1392 from sharetribe/handle-sparse-attributes-in-…
Browse files Browse the repository at this point in the history
…data-update

Handle entity update with sparse attributes
  • Loading branch information
Gnito authored Dec 15, 2020
2 parents 418b37a + ef4366c commit bc88c06
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ way to update this template, but currently, we follow a pattern:

## Upcoming version 2020-XX-XX

- [change] Handle entity update with sparse attributes.
[#1392](https://github.com/sharetribe/ftw-daily/pull/1392)
- [change] Remove react-google-maps dependency. It has not been maintained for 3 years. From now on,
we use Google Maps API directly. However, the default map provider is still Mapbox.
[#1389](https://github.com/sharetribe/ftw-daily/pull/1389)
Expand Down
5 changes: 4 additions & 1 deletion src/util/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ 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: { ...attributes } } : null;
const attributesOld = oldRes.attributes || {};
const attributesNew = newRes.attributes || {};
// Allow (potentially) sparse attributes to update only relevant fields
const attrs = attributes ? { attributes: { ...attributesOld, ...attributesNew } } : null;
const relationships = combinedRelationships(oldRes.relationships, newRes.relationships);
const rels = relationships ? { relationships } : null;
return { id, type, ...attrs, ...rels };
Expand Down

0 comments on commit bc88c06

Please sign in to comment.