JoshData/jot

Conflictless rebase for diff created operations

bombazook opened this issue · 2 comments

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

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:

  • orig = op1.apply(orig)
  • op2 = op2.rebase(op1)
  • orig = op2.apply(orig)

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:

  • op2 = op2.rebase(op1, { document: orig })
  • orig = op1.apply(orig)
  • orig = op2.apply(orig)