Skip to content

Commit a40f268

Browse files
committed
Use a Bookmark class
1 parent 2f80153 commit a40f268

File tree

3 files changed

+382
-332
lines changed

3 files changed

+382
-332
lines changed

shiny/bookmark/_bookmark.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
# * √ `session.bookmark_store`: `url`, `server`, `disable`
2222
# Session hooks -> `onBookmark()`, `onBookmarked()`, `onRestore(), `onRestored()`
2323
# * √ `session.on_bookmark()` # Takes the save state
24+
# * Cancel callback
2425
# * √ `session.on_bookmarked()` # Takes a url
26+
# * Cancel callback
2527
# * `session.onRestore()`
2628
# * `session.onRestored()`
2729
# Session hooks -> Require list of callback functions for each

shiny/express/_stub_session.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
from htmltools import TagChild
66

7+
from shiny.bookmark._bookmark import ShinySaveState
8+
79
from .._namespaces import Id, ResolvedId, Root
810
from ..session import Inputs, Outputs, Session
9-
from ..session._session import SessionProxy
11+
from ..session._session import Bookmark, SessionProxy
1012

1113
if TYPE_CHECKING:
1214
from ..session._session import DownloadHandler, DynamicRouteHandler, RenderedDeps
@@ -44,21 +46,17 @@ def __init__(self, ns: ResolvedId = Root):
4446
# Application-level (not session-level) options that may be set via app_opts().
4547
self.app_opts: AppOpts = {}
4648

47-
self.bookmark_exclude = []
48-
self.bookmark_store = "disable" # TODO: Is this correct?
49+
self.bookmark = BookmarkExpressStub(self)
50+
51+
self.exclude = []
52+
self.store = "disable" # TODO: Is this correct?
4953

5054
def is_stub_session(self) -> Literal[True]:
5155
return True
5256

5357
async def close(self, code: int = 1001) -> None:
5458
return
5559

56-
def _get_bookmark_exclude(self) -> list[str]:
57-
raise NotImplementedError("Please call this only from a real session object")
58-
59-
def do_bookmark(self) -> None:
60-
raise NotImplementedError("Please call this only from a real session object")
61-
6260
# This is needed so that Outputs don't throw an error.
6361
def _is_hidden(self, name: str) -> bool:
6462
return False
@@ -147,3 +145,32 @@ def download(
147145
encoding: str = "utf-8",
148146
) -> Callable[[DownloadHandler], None]:
149147
return lambda x: None
148+
149+
150+
class BookmarkExpressStub(Bookmark):
151+
152+
def _get_bookmark_exclude(self) -> list[str]:
153+
raise NotImplementedError("Please call this only from a real session object")
154+
155+
def on_bookmark(
156+
self,
157+
callback: (
158+
Callable[[ShinySaveState], None]
159+
| Callable[[ShinySaveState], Awaitable[None]]
160+
),
161+
) -> None:
162+
raise NotImplementedError("Please call this only from a real session object")
163+
164+
def on_bookmarked(
165+
self,
166+
callback: Callable[[str], None] | Callable[[str], Awaitable[None]],
167+
) -> None:
168+
raise NotImplementedError("Please call this only from a real session object")
169+
170+
async def update_query_string(
171+
self, query_string: str, mode: Literal["replace", "push"] = "replace"
172+
) -> None:
173+
raise NotImplementedError("Please call this only from a real session object")
174+
175+
async def do_bookmark(self) -> None:
176+
raise NotImplementedError("Please call this only from a real session object")

0 commit comments

Comments
 (0)