Skip to content

Commit d054673

Browse files
committed
pass shared parameter to hotswap
1 parent 616adfa commit d054673

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

examples/example_utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77

88

99
def setup_example_server(
10-
server: Type[AbstractRenderServer], host: str, port: int
10+
server: Type[AbstractRenderServer], host: str, port: int, shared: bool = False,
1111
) -> Tuple[str, AbstractRenderServer, Callable[..., Any]]:
12-
server_instance, mount = imperative_server_mount(
13-
server, host, port, {"access_log": False}, {"cors": True},
14-
)
15-
1612
localhost_idom_path = f"http://{host}:{port}"
1713
jupyterhub_idom_path = path_to_jupyterhub_proxy(port)
18-
1914
path_to_idom = jupyterhub_idom_path or localhost_idom_path
2015

16+
server_instance, mount = imperative_server_mount(
17+
server, host, port, shared, {"cors": True}, {"access_log": False}
18+
)
19+
2120
return path_to_idom, server_instance, mount
2221

2322

examples/introduction.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
"metadata": {},
140140
"outputs": [],
141141
"source": [
142-
"display_href(server_url)"
142+
"display_href(server_url + \"/client/index.html\")"
143143
]
144144
},
145145
{
@@ -760,7 +760,9 @@
760760
"from idom.server.sanic import SharedClientState\n",
761761
"from example_utils import setup_example_server, display_href, pretty_dict_string\n",
762762
"\n",
763-
"shared_server_url, shared_server, mount_shared = setup_example_server(SharedClientState, \"127.0.0.1\", 5678)\n",
763+
"shared_server_url, shared_server, mount_shared = setup_example_server(\n",
764+
" SharedClientState, \"127.0.0.1\", 5678, shared=True\n",
765+
")\n",
764766
"\n",
765767
"def display_shared(element, *args, **kwargs):\n",
766768
" mount_shared(element, *args, **kwargs)\n",

idom/server/__init__.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,30 @@ def imperative_server_mount(
2727
server: Type[_S],
2828
host: str,
2929
port: int,
30+
shared: bool = False,
31+
server_options: Optional[Any] = None,
3032
run_options: Optional[Dict[str, Any]] = None,
31-
server_options: Optional[Dict[str, Any]] = None,
3233
) -> Tuple[_S, Callable[[ElementConstructor], None]]:
33-
mount, element = hotswap()
34-
server_instance = server(element).configure(server_options or {})
34+
"""Set up a server whose view can be swapped out on the fly.
35+
36+
In other words this allows the user to work with IDOM in an imperative manner.
37+
Under the hood this uses the :func:`idom.widgets.common.hotswap` function to
38+
switch out views on the fly.
39+
40+
Parameters:
41+
server: The server type to start up as a daemon
42+
host: The server hostname
43+
port: The server port number
44+
shared: Whether or not all views from the server should be updated when swapping
45+
server_options: Value passed to :meth:`AbstractRenderServer.configure`
46+
run_options: Keyword args passed to :meth:`AbstractRenderServer.daemon`
47+
48+
Returns:
49+
The server instance and a function for swapping out the view.
50+
"""
51+
mount, element = hotswap(shared)
52+
server_instance = server(element)
53+
if server_options:
54+
server_instance.configure(server_options)
3555
server_instance.daemon(host, port, **(run_options or {}))
3656
return server_instance, mount

0 commit comments

Comments
 (0)