Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions shiny/bookmark/_bookmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import warnings
from abc import ABC, abstractmethod
from pathlib import Path
from typing import TYPE_CHECKING, Awaitable, Callable, Literal
from typing import TYPE_CHECKING, Awaitable, Callable, Literal, Optional

from .._docstring import add_example
from .._utils import AsyncCallbacks, CancelCallback, wrap_async
Expand Down Expand Up @@ -167,7 +167,7 @@ def on_restored(
@abstractmethod
async def update_query_string(
self,
query_string: str,
query_string: Optional[str] = None,
mode: Literal["replace", "push"] = "replace",
) -> None:
"""
Expand All @@ -176,7 +176,7 @@ async def update_query_string(
Parameters
----------
query_string
The query string to set.
The query string to set. If `None`, the current bookmark state URL will be used.
mode
Whether to replace the current URL or push a new one. Pushing a new value
will add to the user's browser history.
Expand Down Expand Up @@ -448,9 +448,12 @@ async def invoke_on_restored_callbacks():

async def update_query_string(
self,
query_string: str,
query_string: Optional[str] = None,
mode: Literal["replace", "push"] = "replace",
) -> None:
if query_string is None:
query_string = await self.get_bookmark_url()

if mode not in {"replace", "push"}:
raise ValueError(f"Invalid mode: {mode}")
await self._root_session._send_message(
Expand Down Expand Up @@ -723,7 +726,9 @@ def _restore_context(self) -> RestoreContext | None:
return self._root_bookmark._restore_context

async def update_query_string(
self, query_string: str, mode: Literal["replace", "push"] = "replace"
self,
query_string: Optional[str] = None,
mode: Literal["replace", "push"] = "replace",
) -> None:
await self._root_bookmark.update_query_string(query_string, mode)

Expand Down Expand Up @@ -769,7 +774,9 @@ def on_bookmarked(
return lambda: None

async def update_query_string(
self, query_string: str, mode: Literal["replace", "push"] = "replace"
self,
query_string: Optional[str] = None,
mode: Literal["replace", "push"] = "replace",
) -> None:
# no-op within ExpressStub
return None
Expand Down
Loading