One direction merge

Hi, I’m building an ed-tech platform with collaborative features. The platform is built heavily on YJS and Tiptap. One feature we’ve been excited to attempt is where teachers can create notes and students are able to highlight and comment on notes or link from teachers’ notes back to their own summary notes.

Obviously students shouldn’t be able to see each other’s highlights, comments, etc, which means (I think) that each student needs their own copy of the tiptap YDoc saved in storage.

My thinking is that if a teacher wants to update their note, then the changes should be merged into the student’s copy of the note, but the student’s changes shouldn’t merge back to the teacher’s copy of the note. Is there a nice way to do a one-way merge? Or should I just merge the ydoc and not persist the changes to the teacher’s version in the database? Or is there a better way of structuring this whole feature? Ideally we wouldn’t have to store a copy of the note for every student, but I have no idea how else one would ‘overlay’ the student’s highlight/comment onto the existing document.

I know this is quite vague, hoping someone has done something similar or can give some advice, thanks!

1 Like

Hi @Ferdzzzzzzzz,

As we discussion in the Y Community Meeting, you can implement a one-way merge.

You can create a branch of a Yjs document without ever applying the updates upstream. You can always merge the updates from upstream to your local branch.

However, if your students only make annotations (like comments, highlights, etc…), it makes more sense to store the ranges in a different data structure (e.g. a second Y.Doc). You can refer to positions & ranges of another Y.Doc using relative positions.

1 Like

@dmonad this definitely sounds like the better solution. Struggling to figure it out though, would be great to play with it on one of the meetings when there is time! :smile: Will keep playing with it in the meantime :+1:

1 Like