Skip to content

Maybe change createPatch array replace method #91

@salehi-hassan

Description

@salehi-hassan

Currently, if array has duplicates, it generates the diff from start, but maybe it can skip the repeated part. Although, not sure which result is more performant to apply.

Input:

{
  "name": "Chris Brown",
  "repositories": [
    "repo1",
    "repo2"
  ],
  "address": {
    "street": "Main"
  }
}

Output:

{
  "name": "Christopher Brown",
  "repositories": [
    "repo1",
    "repo2",
    "repo3",
    "repo1",
    "repo2",
    "repo3"
  ]
}

Result:

[
  {
    "op": "replace",
    "path": "/name",
    "value": "Christopher Brown"
  },
  {
    "op": "add",
    "path": "/repositories/0",
    "value": "repo1"
  },
  {
    "op": "add",
    "path": "/repositories/1",
    "value": "repo2"
  },
  {
    "op": "add",
    "path": "/repositories/2",
    "value": "repo3"
  },
  {
    "op": "add",
    "path": "/repositories/-",
    "value": "repo3"
  }
]

Expected result:

[
  {
    "op": "replace",
    "path": "/name",
    "value": "Christopher Brown"
  },
  {
    "op": "add",
    "path": "/repositories/-",
    "value": "repo3"
  },
  {
    "op": "add",
    "path": "/repositories/-",
    "value": "repo1"
  },
  {
    "op": "add",
    "path": "/repositories/-",
    "value": "repo2"
  },
  {
    "op": "add",
    "path": "/repositories/-",
    "value": "repo3"
  }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions