Skip to content

Clean up patch object to only contain modifications #62

Closed
@mrichar1

Description

@mrichar1

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions