-
Notifications
You must be signed in to change notification settings - Fork 454
A specific version of ot-json0 is hardcoded as the basic type #284
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
Comments
We're running on a forked version of const sharedb = require('sharedb');
const sharedbClient = require('sharedb/lib/client');
const richText = require('rich-text');
const json0 = require('forked-ot-json0');
registerTypes(sharedb);
registerTypes(sharedbClient);
function registerTypes(library) {
library.types.register(json0.type);
// ShareDB starts with a default type of JSON0, from its own dependency
// (ie not our forked version). We need to override ShareDB's default with
// our forked JSON0, otherwise we get an "Invalid default type" error on
// connection.
library.types.defaultType = json0.type;
}
export const Backend = sharedb;
export const Client = sharedbClient; However, yes, I wholly agree that there should be an official way of overriding this type. |
Woohoo! The power of Open Source. I knew someone must have faced this at some point. |
Comments from @nateps in weekly meeting:
Further thoughts:
|
This may be a bit extreme, but what if ShareDB did not depend on Put another way, if application code uses ShareDB but doesn't use I recently discovered json1 and text-unicode, which look to be very solid and fresh OT types from @josephg. These may be the best types to use for longer-term development of ShareDB-based applications. |
Currently it looks like this, in both server and client: const json0 = require('fork-of-ot-json0');
const ShareDB = require('sharedb'); // or require('sharedb/lib/client');
ShareDB.types.register(json0.type);
ShareDB.types.defaultType = json0.type; That's not too bad, but what if we had a cleaner API, and made a breaking change that requires application code set the default type, not providing const json0 = require('fork-of-ot-json0');
const ShareDB = require('sharedb'); // or require('sharedb/lib/client');
ShareDB.setDefaultType(json0.type); This could be behind a deprecation flag pre-1.0. Thoughts on this |
I think I'm a fan of the approach where clients negotiate with the server in the connection handshake to set a default type on a per-connection basis. This seems more sensible to me than just setting it across all connections. |
@alecgibson Why would it be preferable to set a default type on a per-connection basis (negotiate in the connection handshake), as opposed to setting it globally for the app (all connections)? I'm having trouble imagining a scenario where that would be preferable. Do you have one in mind? |
I personally think that setting a default type conceptually belongs on the connection, in the same way that a client / server will negotiate eg TLS version / cypher on a per-connection basis. It's some configuration that should be left to the client to decide, because - after all - they'll be the one actually manipulating the type. These are some of the possible trade-offs: Negotiate on handshake
Server dictates default type
|
If you're starting a fresh project, this is not an issue, but I think it makes sense for migrations/rollouts of larger deployments. |
Note: the handshake is useful/necessary for app deployments that upgrade the OT type. At least an error should be thrown if the client and server protocols (OT types) don't match. In a sense, there will be no more "default type", and instead we'll have a type defined per connection. Extra step for mismatched clients: convert op from e.g. json0 to json1 before applying it. |
The json0 appears to be a hard dependency of sharedb (c.f. share/sharedb#284). To handle plain text rather than JSON documents, it appears that we have to register the 'type' with sharedb.
There's currently a bunch of experiments going on around adding presence to ot-json0. One of the things I've come across is that ShareDB currently has a hard dependency on the ot-json0 NPM package, meaning that if we want to replace it with another implementation, we need to also fork the ShareDB package, which is unfortunate.
Here's the code that errors out:
(lib/client/connection.js:198)
We can either remove that (I did, and it worked), or instead of this line in lib/types.js:
we might think about letting the user (optionally) supply a default type when configuring ShareDB?
Currently I've just been looking at replacing the base ot-json0 implementation with a type that is almost identical, just with added presence. However, I don't actually know enough about the requirements for a defaultType - does there have to be one? Does it just need to "exist" or to implement a certain interface (beyond the general OT interface)? Could I specify "ot-text" as a default type?
Thanks!
The text was updated successfully, but these errors were encountered: