Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JSON1 #9

Open
curran opened this issue Mar 8, 2022 · 1 comment
Open

Support JSON1 #9

curran opened this issue Mar 8, 2022 · 1 comment

Comments

@curran
Copy link

curran commented Mar 8, 2022

What would it take to make this library work with json1?

Initial exploration reveals these places might need to be changed:

@highsea
Copy link

highsea commented Feb 23, 2024

Need to pay attention to modification:

// This package also needs modification : https://github.com/ottypes/json0-to-1/issues/2
const json0to1 = require('ot-json0-to-1');
const json1 = require('ot-json1');
...
...
StringBinding.prototype._onOp = function (op, source) { 
  if (source === this) return;
  if (op.length === 0) return;
  json1.type.apply(json1.type.create(this.doc.data), op);
  this._parseParentOp();
};

StringBinding.prototype._insert = function (index, text) {
  var path = this.path.concat(index);
  var op = { p: path, si: text };
  const json1op = json0to1([op]); // Change ot command
  this.doc.submitOp(json1op, { source: this });
};

...

StringBinding.prototype._remove = function (index, text) { 
  var path = this.path.concat(index);
  var op = { p: path, sd: text };
  const json1op = json0to1([op]);
  this.doc.submitOp(json1op, { source: this });
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants