Add optional on_reset argument to YRoom get methods
#152
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds a new option
on_resetcallback argument to theYRoompublic get methods. The new signatures of these methods are:get_awareness(on_reset: Callable[[pycrdt.Awareness], Any] | None = None)async get_jupyter_ydoc(on_reset: Callable[[YBaseDoc], Any] | None = None)async get_ydoc(on_reset: Callable[[pycrdt.Doc], Any] | None = None)These
on_resetcallbacks, if passed, will be called with the new object of that type whenever the YDoc is reset.on_resettoget_awareness()will result inon_resetbeing called with the newpycrdt.Awarenessobject after the YDoc is reset.get_jupyter_ydoc()andget_ydoc(), which will be called with the newYBaseDocandpycrdt.Docobjects after the YDoc is reset.Currently, a YDoc is reset only when an out-of-band change occurs on the source document. However, we may implement auto-resets in the future to save memory (see #114).
Technical details
This PR adds a
mock_server_docs_app: MockServerDocsAppfixture that simulates the rootServerDocsAppdefined inapp.py. This can be passed as theparentargument to any singleton "manager" class initialized by the rootExtensionApp, making it much easier to write integration tests in the future.This PR uses this to define new fixtures for
YRoomandYRoomManager, and adds a unit test verifying the behavior of theon_resetcallback arguments.