-
Notifications
You must be signed in to change notification settings - Fork 19
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
[bug] Invalid patch produced from array.splice() call #68
Comments
I did see that this may be intentional from: #65 But I think the generated patch should not include "length" for it to match the JSON patch spec? FWIW immer does handle this case with "remove". |
hi @davidye , by default, Mutative’s patch generation rules differ slightly from the JSON Patch spec. The doc: https://github.com/unadlib/mutative?tab=readme-ov-file#createstate-fn-options. You can set const x: string[] = ['a'];
const [_, patches] = create(
x,
(draft) => {
draft.splice(0, 1);
},
{
enablePatches: {
arrayLengthAssignment: false,
},
}
);
console.log(patches); // [ { op: 'remove', path: [ 0 ] } ] Here #6 is more related discussion. |
|
Oh I see, thank you! Excellent library by the way this is exactly what I was looking for. |
This produces:
[{ op: "replace", path: "length"], value: 0 }]
When it should be a "remove" operation
The text was updated successfully, but these errors were encountered: