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 Nov 23, 2023
1 parent d9762a1 commit cf7d2bd
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 @@ -110,6 +110,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 @@ -121,6 +131,17 @@ def path(self, value: str) -> None:
with self._ydoc.begin_transaction() as t:
self._ystate.set(t, "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 @@ -254,7 +254,7 @@ def set(self, value: Dict) -> None:
self._ymeta.pop(t, key)
if cells_len:
self._ycells.delete_range(t, 0, cells_len)
for key in [k for k in self._ystate if k not in ("dirty", "path")]:
for key in [k for k in self._ystate if k not in ("dirty", "path", "file_id")]:
self._ystate.pop(t, key)

# initialize document
Expand Down

0 comments on commit cf7d2bd

Please sign in to comment.