-
Notifications
You must be signed in to change notification settings - Fork 22
Doc awareness #277
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
Doc awareness #277
Changes from 4 commits
7845ff7
dc91692
3aa8387
c1b0496
a8af145
8c74b23
4612306
8c780d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ | |||||
from abc import ABC, abstractmethod | ||||||
from typing import Any, Callable, Dict, Optional | ||||||
|
||||||
from pycrdt import Doc, Map, Subscription, UndoManager | ||||||
from pycrdt import Awareness, Doc, Map, Subscription, UndoManager | ||||||
|
||||||
|
||||||
class YBaseDoc(ABC): | ||||||
|
@@ -20,17 +20,22 @@ class YBaseDoc(ABC): | |||||
_subscriptions: Dict[Any, Subscription] | ||||||
_undo_manager: UndoManager | ||||||
|
||||||
def __init__(self, ydoc: Optional[Doc] = None): | ||||||
def __init__(self, ydoc: Optional[Doc] = None, awareness: Optional[Awareness] = None): | ||||||
""" | ||||||
Constructs a YBaseDoc. | ||||||
|
||||||
:param ydoc: The :class:`pycrdt.Doc` that will hold the data of the document, if provided. | ||||||
:type ydoc: :class:`pycrdt.Doc`, optional. | ||||||
:param awareness: The :class:`pycrdt.Awareness` that share non persistent data | ||||||
between clients. | ||||||
:type awareness: :class:`pycrdt.Awareness`, optional. | ||||||
""" | ||||||
if ydoc is None: | ||||||
self._ydoc = Doc() | ||||||
else: | ||||||
self._ydoc = ydoc | ||||||
self._awareness = awareness | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should just have:
Suggested change
And remove the getter and setter as they do nothing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe we should only remove the setter, to make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the getter and setter. |
||||||
|
||||||
self._ystate = self._ydoc.get("state", type=Map) | ||||||
self._subscriptions = {} | ||||||
self._undo_manager = UndoManager(doc=self._ydoc, capture_timeout_millis=0) | ||||||
|
@@ -74,6 +79,26 @@ def ydoc(self) -> Doc: | |||||
""" | ||||||
return self._ydoc | ||||||
|
||||||
@property | ||||||
def awareness(self) -> Awareness | None: | ||||||
brichet marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
""" | ||||||
Returns the awareness. | ||||||
|
||||||
:return: The document's awareness. | ||||||
:rtype: :class:`pycrdt.Awareness` or None. | ||||||
""" | ||||||
return self._awareness | ||||||
|
||||||
@awareness.setter | ||||||
def awareness(self, value: Awareness) -> None: | ||||||
""" | ||||||
Sets the awareness. | ||||||
|
||||||
:param value: The awareness to set. | ||||||
:type value: :class:`pycrdt.Awareness`. | ||||||
""" | ||||||
self._awareness = value | ||||||
|
||||||
@property | ||||||
def source(self) -> Any: | ||||||
""" | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.