Comments (5)
Thanks for reporting this. When it comes to the order for the patches in the shim, they should be reversed (as you pointed out).
When it comes to the issue of the length
property, I'm not sure which way to go. length
is not an enumerable property, so should we generate a patch for it? As it is ignored by JSON.stringify(), the default behaviour should perhaps be that it is ignored by the JSON-Patch generator.
WDYT?
from json-patch.
The length
property has it's own ticket: #14. I think it should be removed from the output
from json-patch.
Native Object.observe
is reporting items removed with Array.prototype.splice
in reverse order. In contrary, the shimmed version reports removed items in the natural order.
As we see here, different implementations may produce different results depending on the direction of the algorithm. When more browsers support Object.observe
, that may get even more diverse if you compare the results as strings.
To me, the only logical way to sort patches
is by the time of detection. Because we have no control over order of changes made internally in Array.prototype.splice
, we need to agree that this may be reverse order if the browser implements it so.
Native Object.observe
may know the real order of changes, but shim may only traverse the tree on time intervals, and then report the changes in natural (alphabetical) order.
Thus, in my opinion this issue should be Won't fix, but I leave this open for discussion.
from json-patch.
Now I have a new light on this issue... Considering this array:
var obj = {
items: ["a", "b"]
}
Calling this will work OK:
jsonpatch.apply(obj, [
{
"op": "remove",
"path": "/items/1"
},
{
"op": "remove",
"path": "/items/0"
}
])
But calling this will call exception:
jsonpatch.apply(obj, [
{
"op": "remove",
"path": "/items/0"
},
{
"op": "remove",
"path": "/items/1"
}
])
Because after first patch is applied, index 1
no longer exists in the items array. I think we need to change the shim implementation to iterate backwards so the array changes are always reported in descending index order.
from json-patch.
Fixed in 0.3.4
from json-patch.
Related Issues (20)
- Inefficient patch encoding when prepending to arrays HOT 2
- rrrr HOT 1
- Add performance comparison with jsondiffpatch
- Array patching, over empty elements.. HOT 2
- Any plans for a new release? HOT 1
- Maybe it's already discussed, but anyone think of how to patch array member in a more flexible approach?
- Release 3.1.1 request based on PR merged of #262 HOT 2
- Inaccurate documentation HOT 1
- Error index always 0? HOT 1
- Optional observe callback not called HOT 1
- applyPatch() validator index is not incrementing
- Backport fix for GHSA-8gh8-hqwg-xf34 to v2 HOT 5
- package.json should use `conditional exports`, else esm won't work inexplicitly HOT 1
- Node12+ import documentation incorrect
- Documentation for `generate` mentions wrong signature
- auto add tests to "add/remove" operations like for "replace"
- Mixing default exports and named exports breaks parcel HOT 2
- Attempting to use if mirror has a toJSON and object does not breaks HOT 2
- applying a replace patch is inconsistent with path="" and path="/"
- Is the project dead ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-patch.