JoshData / jot

JSON Operational Transformation (JOT)
353 stars 34 forks source link

Conflictless rebase for diff created operations #13

Closed bombazook closed 5 years ago

bombazook commented 6 years ago

Hello. I just created a small Ruby wrapper (https://github.com/bombazook/jot-ruby) for your library and experimenting with that. Why doesn't that js code work (maybe it shouldn't?):

let orig =  {a: [{b:"ololo"}, 1]}
let op1 = jot.diff(orig, {a: [2, {b:"hololo"}]})
let op2 = jot.diff(orig, {a: [{b:"ololos"}, 2]})
let rebase1 = op1.rebase(op2, {document: orig}) // it is equal to op1 for some reason
let rebase2 = op2.rebase(op1, {document: orig})
// at this point I have 2 different rebases 
// (I thought it should be the same) 
// and the second one doesn't work:
rebase2.apply(orig) 
// raises an exception 
// TypeError: Cannot read property 'slice' of undefined
JoshData commented 6 years ago

Neat.

Keep in mind that since JOT is licensed under the GPL, a derivative library like yours must be also, and as well as any software that uses it (roughly speaking).

You're doing too much in your example. The normal sequence is:

JoshData commented 6 years ago

I left out the second argument to rebase by accident. You had that right. And because I left it out I rearranged the lines in a way that makes less sense when you put it in. So it really should be: