GithubHelp home page GithubHelp logo

changesets's Introduction

👋 Hi, I’m @marcelklehr

I work on Open Source projects that further freedom and privacy and allow people to use the fruits of technology with sovereignty. This is my small contribution to a world where people are not dependent on big corporations to live a life eased by technology.

changesets's People

Contributors

croikle avatar dcohenb avatar jonasp avatar marcelklehr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

changesets's Issues

"transformAgainst" doesn't work as expected

var Changeset = changesets.Changeset;
var dmp = new diff_match_patch();

var text1 = "Hello adventurer!",
    text2 = "Hello treasured adventurer!",//suppose user A changes text1 to text2 
    text3 = "Good day adventurers, y'all!";//suppose user B changes text1 to text3

var diff1_2 = dmp.diff_main(text1, text2);
var diff1_3 = dmp.diff_main(text1, text3);

var cs1_2 = Changeset.fromDiff(diff1_2);
var cs1_3 = Changeset.fromDiff(diff1_3);

var textFinal_1 = cs1_2.transformAgainst(cs1_3).apply(text3);
var textFinal_2 = cs1_3.transformAgainst(cs1_2).apply(text2);

console.log(textFinal_1 === textFinal_2);//the result we expected to be true, but actually false

Meaningfull errors

Sometimes, things go worng. If they do, this library should be helpful in fixing them.
This means specifying as precisely as possible where there is an error in the changeset and what exactly the problem is.

"transformAgainst" doesn't work as expected

var Changeset = changesets.Changeset;
var dmp = new diff_match_patch();

var text1 = "Hello adventurer!",
    text2 = "Hello treasured adventurer!",//suppose user A changes text1 to text2 
    text3 = "Good day adventurers, y'all!";//suppose user B changes text1 to text3

var diff1_2 = dmp.diff_main(text1, text2);
var diff1_3 = dmp.diff_main(text1, text3);

var cs1_2 = Changeset.fromDiff(diff1_2);
var cs1_3 = Changeset.fromDiff(diff1_3);

var textFinal_1 = cs1_2.transformAgainst(cs1_3).apply(text3);
var textFinal_2 = cs1_3.transformAgainst(cs1_2).apply(text2);

console.log(textFinal_1 === textFinal_2);//the result we expected to be true, but actually false

unpacking does not work for operation length > 35

The regex for unpacking of operations is /(+|-|=)\w+?/g .
If the length of an operation is > 35 the base 36 encoding gives two characters, say "10" for 36.

If we have an operation string like "=10+4|..." , the present regex matches only the first character of the length: [ "=1", "+4" ].

This is easily reproducible when operating on longer (>35) strings.

Dropping the optional - ?: /(+|-|=)\w+/g matches the whole encoded length as intended. Comparing this with the pack() function, the length is never omitted, so I think this would be the right thing to do.

Better use op streams instead of an op heap...

context-equivalent operations packed together forming one "changeset" is nice, but it doesn't play that well with merging changesets as well as other stuff.

Plus, all this transform stuff might be way simpler to do with a stream like approach (meaning you have a cursor that kinda zooms through your document, moved by the operations as they insert or delete stuff or leave stuff untouched). This means operations in a changeset will have an order!

  • inclusion transform
  • exclusion transform
  • invert
  • pack/unpack
  • merge
  • tie breaker

Closed

I'm just interested is it possible to use changesets module to JSON objects rather that plain text? My JSON is look like the following:

var a = {
  name: 'John',
  age: 55,
  tags: ['tag1', 'tag2', 'tag3'],
  events: {
    add: "four",
    create: 3
  }
};

Question: why must the input length match the expected length?

I'm wondering why the following code example is not considered to be correct:

var Changeset = require('changesets').Changeset;
str = 'Hans Peter';
cs = Changeset.create().retain(4).insert(' Jürgen').end();
cs.apply(str);
Error: Input length doesn't match expected length. expected: 4; actual: 10

I must retain the rest of the string to make it work:

cs = Changeset.create().retain(4).insert(' Jürgen').retain(6).end();

If I remove the validation it works like expected.

Is there a good reason for this validation?

Best Regards,
Oliver

"transformAgainst" doesn't work as expected

var Changeset = changesets.Changeset;
var dmp = new diff_match_patch();

var text1 = "Hello adventurer!",
    text2 = "Hello treasured adventurer!",//suppose user A changes text1 to text2 
    text3 = "Good day adventurers, y'all!";//suppose user B changes text1 to text3

var diff1_2 = dmp.diff_main(text1, text2);
var diff1_3 = dmp.diff_main(text1, text3);

var cs1_2 = Changeset.fromDiff(diff1_2);
var cs1_3 = Changeset.fromDiff(diff1_3);

var textFinal_1 = cs1_2.transformAgainst(cs1_3).apply(text3);
var textFinal_2 = cs1_3.transformAgainst(cs1_2).apply(text2);

console.log(textFinal_1 === textFinal_2);//the result we expected to be true, but actually false

Invert

Hello,

When i make an invert of a simple OT +2:2:c:0, i obtain an ot -2:2:c:0. I think it should be -2:3:c:0 in order to be possible to do :

var text = 'ab',
ot = cs.text.Changeset.unpack('+2:2:c:0');

text = ot.apply(text);
text = ot.invert().apply(text);

// text should be equal to 'ab'

Is this possible to support changes from ckeditor ??

Thanks for ur work. I read the doc but still not sure about this, I want to implement a editor could save diff(patches) list in database which is not required to be collaborative, so , can I use this for ckeditor?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.