Skip to content

Commit

Permalink
Add optional file ID to document state
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed May 15, 2024
1 parent a3c01bc commit 8189524
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions jupyter_ydoc/ybasedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ def path(self) -> Optional[str]:
"""
return self._ystate.get("path")

@property
def file_id(self) -> Optional[str]:
"""
Returns document's file ID.
:return: Document's file ID.
:rtype: Optional[str]
"""
return self._ystate.get("file_id")

@path.setter
def path(self, value: str) -> None:
"""
Expand All @@ -119,6 +129,17 @@ def path(self, value: str) -> None:
"""
self._ystate["path"] = value

@file_id.setter
def file_id(self, value: str) -> None:
"""
Sets document's file ID.
:param value: Document's file ID.
:type value: str
"""
with self._ydoc.begin_transaction() as t:
self._ystate.set(t, "file_id", value)

@abstractmethod
def get(self) -> Any:
"""
Expand Down
2 changes: 1 addition & 1 deletion jupyter_ydoc/ynotebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def set(self, value: Dict) -> None:
# clear document
self._ymeta.clear()
self._ycells.clear()
for key in [k for k in self._ystate.keys() if k not in ("dirty", "path")]:
for key in [k for k in self._ystate.keys() if k not in ("dirty", "path", "file_id")]:
del self._ystate[key]

# initialize document
Expand Down

0 comments on commit 8189524

Please sign in to comment.