-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
I was looking at options to squash the JSON Patches generated in my application (using mobx-state-tree, and I came across this library. When adding a child object, and then setting a value within that object, it generates an add operation (with the value as the object) followed by replace operation(s). If I squash the patches, I would expect it result in a single add operation patch with the value being the object with the last replaced value. But the library generates 2 operations, one add and one replace.
I would think that this is a common issue. Do you think the library can squash operations on a object?
const squash = require('json-squash');
const patch = [
{ "op": "add", "path": "/a/b", "value": {c: 1}},
{ "op": "replace", "path": "/a/b/c", "value": 12 },
{ "op": "replace", "path": "/a/b/c", "value": 123 },
{ "op": "replace", "path": "/a/b/c", "value": 1234 },
{ "op": "replace", "path": "/a/b/c", "value": 12345 },
];
const squashed = squash(patch);
Expected
[{"op":"add","path":"/a/b","value":{"c":12345}}]
Actual
[{"op":"add","path":"/a/b","value":{"c":1}},{"op":"replace","path":"/a/b/c","value":12345}]
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels