Skip to content

Commit dddafe6

Browse files
committed
Update _bookmark.py
1 parent 25ba8b4 commit dddafe6

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

shiny/bookmark/_bookmark.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
# {values} -> dict (where as in R is an environment)
1515
# √ values is a dict!
1616
# {exclude} -> Requires `session.setBookmarkExclude(names)`, `session.getBookmarkExclude()`
17-
# * `session.setBookmarkExclude(names)`
17+
# * `session.setBookmarkExclude(names)` TODO:
1818
# * `session.getBookmarkExclude()`
19+
# * `session.bookmark_exclude` value?
20+
# Using a `.bookmark_exclude = []` and `._get_bookmark_exclude()` helper that accesses a `._bookmark_exclude_fns` list of functions which return scoped bookmark excluded values
21+
# Enable bookmarking hooks:
22+
# * types: `url`, `server`, `disable`
23+
# * where to store it? `session` object feels too late. `App` may not exist yet.
1924
# Session hooks -> `onBookmark()`, `onBookmarked()`, `onRestore(), `onRestored()`
20-
# * `session.onBookmark()`
21-
# * `session.onBookmarked()`
25+
# * `session.onBookmark()` TODO:
26+
# * `session.onBookmarked()` TODO:
2227
# * `session.onRestore()`
2328
# * `session.onRestored()`
2429
# Session hooks -> Require list of callback functions for each
@@ -47,7 +52,8 @@
4752

4853
class ShinySaveState:
4954
# session: ?
50-
# WOuld get us access to inputs, possibly app dir, registered on save / load classes.
55+
# * Would get us access to inputs, possibly app dir, registered on save / load classes (?), exclude
56+
#
5157
input: Inputs
5258
values: dict[str, Any]
5359
exclude: list[str]
@@ -78,7 +84,10 @@ def _call_on_save(self):
7884
with isolate():
7985
self.on_save(self)
8086

81-
# def _get_save_interface(self) -> Callable[[str, ]]
87+
def _exclude_bookmark_value(self):
88+
# If the bookmark value is not in the exclude list, add it.
89+
if "._bookmark_" not in self.exclude:
90+
self.exclude.append("._bookmark_")
8291

8392
async def _save_state(self) -> str:
8493
"""
@@ -99,11 +108,11 @@ async def save_state_to_dir(state_dir: Path) -> None:
99108

100109
self._call_on_save()
101110

102-
if self.exclude.index("._bookmark_") == -1:
103-
self.exclude.append("._bookmark_")
111+
self._exclude_bookmark_value()
104112

105113
input_values_json = self.input._serialize(
106-
exclude=self.exclude, state_dir=None
114+
exclude=self.exclude,
115+
state_dir=self.dir,
107116
)
108117
assert self.dir is not None
109118
with open(self.dir / "input.pickle", "wb") as f:
@@ -158,13 +167,15 @@ async def _encode_state(self) -> str:
158167
# Allow user-supplied onSave function to do things like add state$values.
159168
self._call_on_save()
160169

161-
if self.exclude.index("._bookmark_") == -1:
162-
self.exclude.append("._bookmark_")
170+
self._exclude_bookmark_value()
163171

164172
input_values_serialized = await self.input._serialize(
165-
exclude=self.exclude, state_dir=None
173+
exclude=self.exclude,
174+
# Do not include directory as we are not saving to disk.
175+
state_dir=None,
166176
)
167177

178+
# Using an array to construct string to avoid multiple serial concatenations.
168179
qs_str_parts: list[str] = []
169180

170181
# If any input values are present, add them.

0 commit comments

Comments
 (0)