ottypes / json0

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

Helper to generate OTs between two states? #17

Closed ronag closed 6 years ago

ronag commented 8 years ago

Are there any available helpers for e.g. calculating the required OTs between two strings?

curran commented 7 years ago

I believe Racer has a function that does this https://github.com/derbyjs/racer/blob/07c1e6d7ff56a3f48c3f259e6a07efaa1da2a551/lib/Model/setDiff.js#L36

curran commented 6 years ago

@ronag This library does exactly what you describe, and more https://github.com/kbadk/json0-ot-diff

josephg commented 6 years ago

Its also a bad idea in my opinion.

The problem is that there are often multiple ways you could transform one object into another - for example, the list [1,2,3] could be transformed into the list [1,3,2] either by replacing the list, moving the 3 backwards, moving the 2 forwards, deleting the 2 and reinserting it or deleting the 3 and reinserting it. The OT code will do slightly different things in the face of concurrent edits in all of these cases, to preserve the intent of the user. Eg, if I concurrently insert something between the 2 and the 3 while you make your change, what do you think the resulting list should look like? The answer often differs based on the intent of your edit!

curran commented 6 years ago

@josephg Here's a context where this feature would be useful - generating "meta-ops" that bounce across distant versions for computing a snapshot of a desired version efficiently - See https://github.com/share/sharedb/issues/223 .

image

In this context, it doesn't matter which of the possible ways of transforming one object into another is used. As long as they do transform correctly when applied.

The concerns you raise relate only to the case of concurrent edits, which is IMO not where this feature would be used.

Anyway it's great to hear your voice here! Thanks for your work around ShareDB and OT, it's a great foundation for lots if interesting product features.