ottypes / json0

Version 0 of the JSON OT type
447 stars 64 forks source link

Why the delete operation needs an object? #33

Open nnseva opened 4 years ago

nnseva commented 4 years ago

Let's imagine that the data contains a very big branch, f.e. {key: {a:1,b:2,...,z:27}, other:...}

We are going to delete the whole branch "key" for some reason. As I understand, the operation then should look like {p:["key"], od:{a:1,b:2,...,z:27}}.

But for the delete operation, the logically required information is the only key of the deleted item. The deleted object content is the extra info which is not necessary for the operation.

It was probably useful to exclude repeating object content for the delete operation and replace it by something neutral, like logical true.

{p:["key"], od:true}

It looks much more compact and logical.

josephg commented 4 years ago

The reason it works this way is so operations can be inverted, which makes many features like undo easy to implement. I’m not sure about the state of the codebase now, but for a time the code would function just fine the way you suggest too. (It doesn’t need to know what content was deleted to support compose/transform/apply.)