Skip to content

Commit 3de1378

Browse files
committed
Docs
1 parent ab42bff commit 3de1378

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

shiny/bookmark/_bookmark.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,16 @@ class Bookmark(ABC):
8686

8787
# TODO: Barret - This feels like it needs to be a weakref
8888
_session_root: Session
89+
"""
90+
The root session object (most likely a `AppSession` object).
91+
"""
8992

9093
_store: BookmarkStore | MISSING_TYPE
94+
"""
95+
Session specific bookmark store value.
96+
97+
This value could help determine how session state is saved. However, app authors will not be able to change how the session is restored as the server function will run after the session has been restored.
98+
"""
9199

92100
@property
93101
def store(self) -> BookmarkStore:
@@ -103,20 +111,33 @@ def store(self, value: BookmarkStore) -> None:
103111
self._store = value
104112

105113
_proxy_exclude_fns: list[Callable[[], list[str]]]
114+
"""Callbacks that BookmarkProxy classes utilize to help determine the list of inputs to exclude from bookmarking."""
106115
exclude: list[str]
116+
"""A list of scoped Input names to exclude from bookmarking."""
107117

108118
_on_bookmark_callbacks: AsyncCallbacks
109119
_on_bookmarked_callbacks: AsyncCallbacks
110120
_on_restore_callbacks: AsyncCallbacks
111121
_on_restored_callbacks: AsyncCallbacks
112122

113-
_restore_context: RestoreContext | None
123+
_restore_context_value: RestoreContext | None
124+
"""
125+
Placeholder value that should only be manually set within the session's `init` websocket message.
126+
"""
127+
128+
@property
129+
def _restore_context(self) -> RestoreContext | None:
130+
"""
131+
A read-only value of the session's RestoreContext object.
132+
"""
133+
return self._root_bookmark._restore_context_value
114134

115135
async def __call__(self) -> None:
116136
await self._root_bookmark.do_bookmark()
117137

118138
@property
119139
def _root_bookmark(self) -> "Bookmark":
140+
"""The base session's bookmark object."""
120141
return self._session_root.bookmark
121142

122143
def __init__(self, session_root: Session):
@@ -125,7 +146,7 @@ def __init__(self, session_root: Session):
125146
super().__init__()
126147
# TODO: Barret - Q: Should this be a weakref; Session -> Bookmark -> Session
127148
self._session_root = session_root
128-
self._restore_context = None
149+
self._restore_context_value = None
129150
self._store = MISSING
130151

131152
self._proxy_exclude_fns = []
@@ -276,6 +297,15 @@ def __init__(self, session_root: Session):
276297
super().__init__(session_root)
277298

278299
def _create_effects(self) -> None:
300+
"""
301+
Create the bookmarking `@reactive.effect`s for the session.
302+
303+
Effects:
304+
* Call `session.bookmark()` on the bookmark button click.
305+
* Show an error message if the restore context has an error.
306+
* Invoke the `@session.bookmark.on_restore` callbacks at the beginning of the flush cycle.
307+
* Invoke the `@session.bookmark.on_restored` callbacks after the flush cycle completes.
308+
"""
279309
# Get bookmarking config
280310
if self.store == "disable":
281311
return

shiny/bookmark/_restore_state.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,14 @@ async def from_query_string(query_string: str) -> "RestoreContext":
161161
def flush_pending(self) -> None:
162162
self.input.flush_pending()
163163

164-
# Returns a dict representation of the RestoreContext object. This is passed
165-
# to the app author's onRestore function. An important difference between
166-
# the RestoreContext object and the dict is that the former's `input` field
167-
# is a RestoreInputSet object, while the latter's `input` field is just a
168-
# list.
169-
170164
def as_state(self) -> RestoreContextState:
165+
"""
166+
Returns a dict representation of the RestoreContext object. This is passed
167+
to the app author's onRestore function. An important difference between
168+
the RestoreContext object and the dict is that the former's `input` field
169+
is a RestoreInputSet object, while the latter's `input` field is just a
170+
list.
171+
"""
171172
return RestoreContextState(
172173
# Shallow copy
173174
input={**self.input.as_dict()},

0 commit comments

Comments
 (0)