Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up patch object to only contain modifications #62

Closed
mrichar1 opened this issue May 28, 2019 · 1 comment · Fixed by #79
Closed

Clean up patch object to only contain modifications #62

mrichar1 opened this issue May 28, 2019 · 1 comment · Fixed by #79
Labels
enhancement New feature or request

Comments

@mrichar1
Copy link
Owner

Inspired by #59 I've been thinking more about how we handle PATCH data.

When making a patch, it may be useful to be able to 'clean' the patch object, so that it only contains modifications.

This is useful for the workflow where a record is fetched from the API and stored, then the get getter returns a copy, which then has a single attribute modified, and is then used in a patch action. It makes sense for the patch to only contain the changed attribute, and not be the whole store object (this prevents accidental pushes of stale data to the store, and is more efficient).

At it's simplest, there should be a config option, which, if enabled compares attributes in the patch and the store, and keeps only those that are 'different'.

To begin with, this should only consider attributes, but longer term we may want to add further functionality:

  1. look at changes to relationship links (e.g. modifying _jv/relationships/author from {type: 'author', id: '1'} to {type: 'author', id: '2'}
  2. look at changes to relationship data (where 'followed' relationship data in the the root is modified, generate a 2nd patch targeted against the related object's URL).

The first part should be easy to implement, so will begin work on a PR.

@mrichar1 mrichar1 added the enhancement New feature or request label May 28, 2019
@mrichar1
Copy link
Owner Author

mrichar1 commented Jul 2, 2019

I've kept this open as it's likely that '#63 probably isn't the 'right' way to do this. Instead a better option would be to have cleanPatch method available for use on a record prior to passing it in as the argument to patch. This would make is useable on a per-record basis, and also make it more flexible in what it can do.

This relies on #65 being addressed first of all, to make helper methods generally available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant