Giter VIP home page Giter VIP logo

json0-ot-diff's People

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

json0-ot-diff's Issues

About support browser environment

hi,I use json0-ot-diff recently.

And I found the json0-ot-diff only supports the NodeJS environment.

so I think why the json0-ot-diff doesn't run Browser environment.

I find the reason is the dependency deep-equal doesn't support the Browser environment,therefore, the json0-ot-diff is restricted by deep-equal.

Can the json0-ot-diff provide an option to replace deep-equal with another library? (like isEqual of Lodash.) This will support more environments. :)

Path related issue with inverted operations

Hey @kbadk,

The issue I am having is with lines 87-90. The code works fine for every other scenario I've tested, however when trying to apply inverted operations it simply does not work because of the final path value change done at those lines.

Let's look at the following scenario. I want to bold the 'b' letter in the following HTML:

<body>
  <p>abc</p>
</body>

Obtaining:

<body>
  <p>a<strong>b</strong>c</p>
</body>

I'm doing this by running the json0-ot-diff code in the browser and retrieving the diffs between an older version of the JsonML (obtained from the body element) and the newer one (after the bold operation).

The following operations are obtained:

  1. {p:[2,2], ld:"abc", li:"a"} - Ok
  2. {p:[2,3], li: ["STRONG", {}, "b"]} - Ok
  3. {p:[2,5], li: "c"} - Why?

The inverted ops are the following (applied in this exact order):

  1. {p:[2,5], ld: "c"} - Will not apply correctly using the json0.apply(snapshot, op) function because there is nothing at path [2,5]
  2. {p:[2,3], ld: ["STRONG", {}, "b"]} - Ok
  3. {p:[2,2], ld:"a", ld:"abc"} - Ok

What is the reason for increasing / decreasing the final element of the path array by 1 for 'li' / 'ld' operations when if (equal(path, opParentPath))?

EDIT 1:
I've just understood the logic of the code, however I still think that there's a bug regarding the scenario above.

JSON1 OT Diff

json1 seems to be getting more attention lately, would be great to see a differ for json1 and/or advice on how we can contribute.

I'm not well-versed in OT stuff, but this library looks relatively straightforward, which is promising for JSON1

Running diff from null to object fails.

Hi, I've noticed an inconsistency when it comes to handling diffing between null and another type. Following code will succeed

const before = {a: null};
const after = {a: 1};
const op = jd(before, after);
console.log(op);

//Outputs [{"p":["a"],"od":null,"oi":1}] 

Same goes for const after = {a: "text"}

But following will fail

const before = { a: null };
const after = { a: {} };
const op = jd(before, after);
console.log(JSON.stringify(op));

with an error

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
   at diff (https://du8wr.csb.app/node_modules/json0-ot-diff/index.js:196:32)

I've managed to track it down to this line
var keys = new Set([...Object.keys(input), ...Object.keys(output)]);

Object.keys(input) fails due input being null

My expected behaviour is that the diff will behave exactly as when undefined and just generate oi operation at specified path.

If the string contains Unicode Emoji, the index will be misaligned.

Hello, thanks for this useful library!

I'd like to report a bug that I encountered while using it.

 json0diff(['Hello'], ['🤗Hello🤗'], DiffMatchPatch, json1, textUnicode);
// Outputs => [0,{"es":["🤗",6,"🤗"]}]

When this is passed to the apply method of json1, an error message Error: The op is too long for this document will be displayed.

It seems that text-unicode treats emoji as a single character.
changing the index from 6 to 5 works fine.

 [0,{"es":["🤗",5,"🤗"]}]

If it is possible, could you please fix it?

String Operations

Greetings,

I'm wondering, would there be interest in optimizing the case where strings are mutated?

I have a use case where I'd like to preserve the historical ops for mutations on long strings. Currently if a string value is changed, the diff presents a combination of oi and od. This case could be optimized by computing a string diff and presenting the diff as string operations si and sd. The advantage of doing this would be that for large strings, less bandwidth would be used, and the persisted ops would be smaller.

I've researched this a bit, and also posted a thread on the ShareDB mailing list. The library JSDiff has a function called diffChars whose output I think can be translated directly into si and sd ops.

The disadvantage of doing this would be the additional dependency on JSDiff. Perhaps it could be implemented in such a way that the dependency is optional (e.g. if a reference to the diffChars function is passed in, then it's used, otherwise not).

Would such a contribution be welcome here? Thank you.

Could support object array item move?

Every item has an uuid, like

[{ id: 1 }, { id: 2 }, { id: 3 } ]

if move item idx.3 to idx.2 ,then looks like:

[{ id: 1 }, { id: 3 }, { id: 2 } ]

diff should produce

[ [ 1, { p: 0 } ], [ 2, { d: 0 } ] ]

and:

{ 
  a: [{ id: 1 }, { id: 2 }, { id: 3 }],
  b: [{ id: 4 }]
}

move a.idx2 to b, just like:

{
  a: [{ id: 1 }, { id: 3 }],
  b: [{ id: 2 }, { id: 4 }]
}

diff should produce

[ [ 'a', 1, { p: 0 } ], [ 'b', 0, { d: 0 } ] ]

Invertible JSON1 Ops

It occurred to me that the JSON1 support in this library could be enhanced such that it generates invertible JSON1 ops.

This could be done by invoking makeInvertible.

This enhancement would pave the way towards collaborative undo/redo, which is the use case I have in mind for this.

Top level string test is failing

Interestingly, the top level string test appears to have been failing ever since it was introduced in d955810 . It's failing today in master, and if you check out that commit, it's failing there too. No idea why... It should probably be fixed. I'm not sure if the expected value is wrong or the output is wrong. It can be verified by applying the ops to a document and seeing what works correctly.

  21 passing (24ms)
  1 failing

  1) Jsondiff
       Operations
         String Mutation (si + sd)
           Top level string:

      AssertionError: expected [ Array(2) ] to deeply equal [ Array(2) ]
      + expected - actual

       [
         {
      -    "p": [
      -      0
      -    ]
      +    "p": []
           "sd": "one"
         }
         {
      -    "p": [
      -      0
      -    ]
      +    "p": []
           "si": "two"
         }
       ]

Prettier

When working with this codebase, there are different formatting conventions in different files (e.g. tabs in tests.js and spaces in index.test.js. Having worked with Prettier in most of my projects, I can advocate for its use as a time saving tool. It formats the code automatically so that we as authors never need to think about formatting. I would suggest that we adopt Prettier in this codebase, as it will make work going forward easier.

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.