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

Maybe change createPatch array replace method #91

Open
salehi-hassan opened this issue Jan 29, 2023 · 0 comments
Open

Maybe change createPatch array replace method #91

salehi-hassan opened this issue Jan 29, 2023 · 0 comments

Comments

@salehi-hassan
Copy link

salehi-hassan commented Jan 29, 2023

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"
  }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant