jupyter_ydoc icon indicating copy to clipboard operation
jupyter_ydoc copied to clipboard

Support document forking

Open davidbrochart opened this issue 1 year ago • 0 comments

See https://github.com/jupyterlab/jupyterlab/issues/16008.

This PR adds an ISharedDocument.provider attribute, which is an IDocumentProvider and which represents the current provider for the document. The IDocumentProvider interface is moved from jupyter-collaboration to jupyter_ydoc (see https://github.com/jupyterlab/jupyter-collaboration/pull/239). I think this is fine since jupyter-collaboration depends on jupyter_ydoc. A YDocument can only have one provider at a time (as before), but the provider can change over time. This is typically done when forking a document: the initial provider (set by the YDrive) connects to the root document, and the new provider connects to the forked document. An ISharedDocument has a root room ID rootRoomId which is set when first connecting to the root room, and a current room ID currentRoomId which can be the root room ID or any other fork of the root room. This way we can say if the document is currently on a fork or on the root, and we know to which (root) room to merge when on a fork. An ISharedDocument has an addFork(forkId) method that sets a key fork_{forkId} on the Y document's state when the provider is asked to fork. This is a way to advertise all the forks of this document, so that any client viewing the document can be notified of a new fork and can connect to it.

davidbrochart avatar Feb 15 '24 13:02 davidbrochart