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

oi replaces even if exists #16

Open
ronag opened this issue Mar 1, 2016 · 3 comments
Open

oi replaces even if exists #16

ronag opened this issue Mar 1, 2016 · 3 comments

Comments

@ronag
Copy link

ronag commented Mar 1, 2016

For {p:PATH, oi:NEWVALUE}

The documentation says:

When inserting, the key must not already be used.

However, if they key exists it currently will overwrite it...

Not sure what the correct behaviour is?

@ronag
Copy link
Author

ronag commented Mar 1, 2016

The problem I have here it that I would like to be able to insert an element into an array without knowing if the array exists or not, and if it doesn't exists it should be created:

Which I thought would be possible with the following:

[{
  p: ['tags'],
  oi: [],
}, {
  p: ['tags', 0],
  li: 'archived',
}],

However, this will always result in tags: ['archived']regardless if previous elements exists or not...

@alecgibson
Copy link
Contributor

As a side-note, this is also a huge problem with inversion. It's currently possible to have:

{
  "tags": ["archived"]
}

and then perform this op on it:

[
  {
    "p": ["tags"],
    "oi": []
  }
]

...resulting in this document:

{
  "tags": []
}

Then when you try to invert the previous operation, the op doesn't know what was originally there when it replaced it, so it just deletes the field, resulting in:

{}

...which is not what I had before.

In my opinion, in the case where a path is being overwritten, json0 should throw, because it violates the integrity of the operation, as demonstrated above.

@alecgibson
Copy link
Contributor

Aha, I've just seen that my issue is probably addressed in this PR: #19

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

2 participants