-
Notifications
You must be signed in to change notification settings - Fork 64
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
Presence #31
base: master
Are you sure you want to change the base?
Presence #31
Conversation
@houshuang I'd like to request your review here, and also I invite you to merge this work back into your fork and continue working on it. I ended up structuring the presence like this: [
'some', 'path', // Path of the presence.
'ot-rich-text', // Subtype of the presence (a registered subtype).
{ // Opaque presence object (subtype-specific structure).
u: '123', // An example of an ot-rich-text presence object.
c: 8,
s: [ [ 1, 1 ], [ 5, 7 ]]
}
] This is based on a suggestion from @josephg over in ottypes/json1#9 . It feels pretty good so far. Note that this approach pushes the management of the user id ( Cheers! |
I'm starting to wonder if maybe this would be a better structure: {
p: ['some', 'path'], // Path of the presence.
t: 'ot-rich-text', // Subtype of the presence (a registered subtype).
s: { // Opaque presence object (subtype-specific structure).
u: '123', // An example of an ot-rich-text presence object.
c: 8,
s: [ [ 1, 1 ], [ 5, 7 ]]
}
} The reason is, in the implementation there ends up being a bunch of logic for isolating these parts from the array, and building up the array from these parts. The implementation (and consumtion actually) of presence would be more straightforward with this structure. It would eliminate the need for the |
The end is in sight:
Possible "Phase II" work (not a priority right now):
|
Makes sense to me. Still wondering about this:
I would prefer a single presence object per user, and I would also like the user information at the top level, because in our case we will be showing a list of users at the left of the page. In fact, the initial presence sent will only be a top-level user object, with no path or subtype, meaning that the user has entered the complex document, but not yet put a cursor anywhere... If we also need the user information duplicated at the subtype level I'm not sure... I understand that it might simplify a bit having an ottype which can both be used as a top-level type, and a delegated subtype, but I'm not sure this is a strong enough argument. Anyway excited to check out more of your code - sorry my comments are coming kind of scattered, I'm alone with the kid this weekend :) |
I think there is already code in that json00 that handles subtypes, but anyway it shouldn't be hard... Main case is object or array deletion, if someone was present on that, then cancel their presence, and for array insertion, if inserted before the index of a presence, increment presence... However, I don't currently have a use-case for this. What I do have a use-case for is just to specify presence at the key level - basically specifying a
then all the stuff within ['question1', 'questionAnswer1'] and ['question2', 'MCQ-answer2'] could change in various ways. Here for question1, I would want a cursor managed by rich-text, for MCQ-answer2 I would just want to specify presence... Theoretically it would be possible to delete the key MCQ-answer2 and thus invalidate my presence, however that would never happen in my code-base... Not sure if this is relevant or not, just thinking aloud. |
Yes, the current approach here is single "cursor" per user. Re: Re: user information duplicated at the subtype level, it would be great to avoid this. However, it might make sense to have the json0 |
Published as https://www.npmjs.com/package/@datavis-tech/ot-json0 if anyone wants to try it out.
|
Here's a demo https://github.com/datavis-tech/json0-presence-demo |
I encountered a bug and spotted an opportunity to improve developer ergonomics in this implementation. datavis-tech/json0-presence-demo#2 Presence was not being transformed, and I did not know why. After some debugging, I realized the wrong type was being passed in. Meaning, when the json0 I propose to add a |
@curran Hi. It seems to me that the ideal case would be that a subtype did not worry about whether it was receiving the presence directly from ShareDB, or "mediated" through ot-json0. Similarly, I think it would be ideal that users did not have to think too deeply about whether the rich text was a top-level document, or used as part of a json0 document, ie. all you should need to do to change the submitPresence function from a top-level document to a path in a json0 field would be to add a path: ['key'] to the object in submitPresence - do you agree with this goal? In that case, the shape of the input to the transformPresence function in a subtype should be the same as the shape of the input to the transformPresence function in ot-json0... However, it's currently not. Let's say the transformPresence function in ot-json0 receives this input: transformPresence({
'text', // Path of the presence.
'ot-rich-text', // Subtype of the presence (a registered subtype).
's':
{ // Opaque presence object (subtype-specific structure).
u: '123', // An example of an ot-rich-text presence object.
c: 8,
s: [ [ 1, 1 ], [ 5, 7 ]]
}
},
[{
p: ['text'],
o: [
{'retain': 31}, {'insert': 'hi'}
],
t: 'rich-text'
}],
true
) Then due to this line (lib/json0.js:677) s: subtypes[presence.t].transformPresence(presence.s, c.o, isOwnOp) the subtype (rich-text) ot-type will be called with transformPresence({
u: '123', // An example of an ot-rich-text presence object.
c: 8,
s: [ [ 1, 1 ], [ 5, 7 ]]
},
[{'retain': 31}, {'insert': 'hi'}],
true
} In my branch I use
So that the op looks identical, and I have my subtype transform always look inside the What do you think? |
Related to ottypes/json1#9 I'd be curious to compare how json0 and json1 compare in terms of the subtype op structure. I was trying to make the presence structure similar to the subtype op structure of json0. There's also the idea of multiple presence entries simultaneously, which I think is a use case that would be nice to be able to support. For example, one user has presence in two editors at a time, one being a textarea and the other being a Quill document. I'm not sure if this ability should be at the level of the ShareDB implementation of presence, or the OT type. Also related to share/sharedb#288 |
I'm following your work with great excitement. This is brilliant stuff. |
Closes issue #30
Builds on PR #25 by @houshuang