ottypes / docs

277 stars 29 forks source link

Update description of transformCursor #26

Closed gkubisa closed 6 years ago

gkubisa commented 6 years ago

Fixes https://github.com/ottypes/docs/issues/25.

The description is a bit verbose now but hopefully makes it easier to understand what the function actually does.

josephg commented 6 years ago

Thanks for the edit!

Thats correct and better documentation for text types, but for something like JSON it doesn't really make sense to think about cursors as moving forwards and backwards. The whole API here is a bit weird, and I'm not sure what the best answer is. I'm going to merge this PR, but I'm not super happy about this design as it stands. I'm not sure what to do with it.

gkubisa commented 6 years ago

Yes, I'm also not particularly happy about that API because it seems to specific to text types.

I'm currently working on adding a generic "presence" support to ShareDB, which forced me to think about this API too. Here's what I came up with:

The Presence for my custom text OT type is { userId: string, selectionStart: number, selectionEnd: numer } but the API above can work with any arbitrary Presence type. For example, if Presence is a number, then transformPresence === transformCursor.

Other optional functions could be added as for operations, eg normalizePresence, denormalizePresence, etc but I'd hold on with that until it's clear that they are needed.