Skip to content

Commit f6a38e7

Browse files
committed
Use App.bookmark_store to be the source of truth for session.bookmark.store; Remove setter for per-session bookmark store value
1 parent 6c4f596 commit f6a38e7

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

shiny/_app.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from ._error import ErrorMiddleware
3232
from ._shinyenv import is_pyodide
3333
from ._utils import guess_mime_type, is_async_callable, sort_keys_length
34-
from .bookmark import _globals as bookmark_globals
34+
from .bookmark._globals import BookmarkStore
3535
from .bookmark._restore_state import (
3636
RestoreContext,
3737
get_current_restore_context,
@@ -113,6 +113,12 @@ def server(input: Inputs, output: Outputs, session: Session):
113113
ui: RenderedHTML | Callable[[Request], Tag | TagList]
114114
server: Callable[[Inputs, Outputs, Session], None]
115115

116+
_bookmark_store: BookmarkStore
117+
118+
@property
119+
def bookmark_store(self) -> BookmarkStore:
120+
return self._bookmark_store
121+
116122
def __init__(
117123
self,
118124
ui: Tag | TagList | Callable[[Request], Tag | TagList] | Path,
@@ -121,7 +127,8 @@ def __init__(
121127
),
122128
*,
123129
static_assets: Optional[str | Path | Mapping[str, str | Path]] = None,
124-
bookmarking: Optional[Literal["url", "query", "disable"]] = None,
130+
# Document type as Literal to have clearer type hints to App author
131+
bookmark_store: Literal["url", "server", "disable"] = "disable",
125132
debug: bool = False,
126133
) -> None:
127134
# Used to store callbacks to be called when the app is shutting down (according
@@ -141,8 +148,8 @@ def __init__(
141148
"`server` must have 1 (Inputs) or 3 parameters (Inputs, Outputs, Session)"
142149
)
143150

144-
if bookmarking is not None:
145-
bookmark_globals.bookmark_store = bookmarking
151+
self._bookmark_store = bookmark_store
152+
146153
self._debug: bool = debug
147154

148155
# Settings that the user can change after creating the App object.
@@ -363,7 +370,7 @@ async def _on_root_request_cb(self, request: Request) -> Response:
363370
request for / occurs.
364371
"""
365372
ui: RenderedHTML
366-
if bookmark_globals.bookmark_store == "disable":
373+
if self.bookmark_store == "disable":
367374
restore_ctx = RestoreContext()
368375
else:
369376
restore_ctx = await RestoreContext.from_query_string(request.url.query)

shiny/bookmark/_bookmark.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,20 @@ class Bookmark(ABC):
9797
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.
9898
"""
9999

100+
# Making this a read only property as 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.
100101
@property
101102
def store(self) -> BookmarkStore:
102-
# Should we allow for this?
103-
# Allows a per-session override of the global bookmark store
104-
if isinstance(self._session_root.bookmark._store, MISSING_TYPE):
105-
return bookmark_globals.bookmark_store
106-
return self._session_root.bookmark._store
103+
"""
104+
App's bookmark store value
107105
108-
@store.setter
109-
def store(self, value: BookmarkStore) -> None:
110-
self._session_root.bookmark._store = value
111-
self._store = value
106+
Possible values:
107+
* `"url"`: Save / reload the bookmark state in the URL.
108+
* `"server"`: Save / reload the bookmark state on the server.
109+
* `"disable"` (default): Bookmarking is diabled.
110+
"""
111+
112+
# Read from the App's bookmark store value.
113+
return self._session_root.app.bookmark_store
112114

113115
_proxy_exclude_fns: list[Callable[[], list[str]]]
114116
"""Callbacks that BookmarkProxy classes utilize to help determine the list of inputs to exclude from bookmarking."""

shiny/bookmark/_globals.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,5 @@
1313
bookmark_load_dir: BookmarkLoadDir | MISSING_TYPE = MISSING
1414

1515
BookmarkStore = Literal["url", "server", "disable"]
16-
# TODO: Barret - Q: Should we have a `enable_bookmarking(store: BookmarkStore)` function?
17-
bookmark_store: BookmarkStore = "disable"
18-
1916

2017
# TODO: Barret; Q: I feel like there could be a `@shiny.globals.on_session_start` decorator that would allow us to set these values.

0 commit comments

Comments
 (0)