|
2 | 2 | from typing import Any, Callable, Dict, Optional, Tuple, Type, TypeVar |
3 | 3 |
|
4 | 4 | from idom.core.element import ElementConstructor |
5 | | -from idom.widgets.common import hotswap |
| 5 | +from idom.widgets.common import multiview, hotswap |
6 | 6 |
|
7 | 7 | from .base import AbstractRenderServer |
8 | 8 |
|
|
23 | 23 | _S = TypeVar("_S", bound=AbstractRenderServer[Any, Any]) |
24 | 24 |
|
25 | 25 |
|
26 | | -def imperative_server_mount( |
| 26 | +def multiview_server( |
27 | 27 | server: Type[_S], |
28 | 28 | host: str, |
29 | 29 | port: int, |
30 | | - shared: bool = False, |
31 | 30 | server_options: Optional[Any] = None, |
32 | 31 | run_options: Optional[Dict[str, Any]] = None, |
33 | | -) -> Tuple[_S, Callable[[ElementConstructor], None]]: |
34 | | - """Set up a server whose view can be swapped out on the fly. |
| 32 | +) -> Tuple[Callable[[ElementConstructor], int], _S]: |
| 33 | + """Set up a server where views can be dynamically added. |
| 34 | +
|
| 35 | + In other words this allows the user to work with IDOM in an imperative manner. |
| 36 | + Under the hood this uses the :func:`idom.widgets.common.multiview` function to |
| 37 | + add the views on the fly. |
| 38 | +
|
| 39 | + Parameters: |
| 40 | + server: The server type to start up as a daemon |
| 41 | + host: The server hostname |
| 42 | + port: The server port number |
| 43 | + server_options: Value passed to :meth:`AbstractRenderServer.configure` |
| 44 | + run_options: Keyword args passed to :meth:`AbstractRenderServer.daemon` |
| 45 | +
|
| 46 | + Returns: |
| 47 | + The server instance and a function for adding views. |
| 48 | + See :func:`idom.widgets.common.multiview` for details. |
| 49 | + """ |
| 50 | + mount, element = multiview() |
| 51 | + server_instance = server(element) |
| 52 | + if server_options: |
| 53 | + server_instance.configure(server_options) |
| 54 | + server_instance.daemon(host, port, **(run_options or {})) |
| 55 | + return mount, server_instance |
| 56 | + |
| 57 | + |
| 58 | +def hotswap_server( |
| 59 | + server: Type[_S], |
| 60 | + host: str, |
| 61 | + port: int, |
| 62 | + server_options: Optional[Any] = None, |
| 63 | + run_options: Optional[Dict[str, Any]] = None, |
| 64 | +) -> Tuple[Callable[[ElementConstructor], None], _S]: |
| 65 | + """Set up a server where views can be dynamically swapped out. |
35 | 66 |
|
36 | 67 | In other words this allows the user to work with IDOM in an imperative manner. |
37 | 68 | Under the hood this uses the :func:`idom.widgets.common.hotswap` function to |
38 | | - switch out views on the fly. |
| 69 | + swap the views on the fly. |
39 | 70 |
|
40 | 71 | Parameters: |
41 | 72 | server: The server type to start up as a daemon |
42 | 73 | host: The server hostname |
43 | 74 | port: The server port number |
44 | | - shared: Whether or not all views from the server should be updated when swapping |
45 | 75 | server_options: Value passed to :meth:`AbstractRenderServer.configure` |
46 | 76 | run_options: Keyword args passed to :meth:`AbstractRenderServer.daemon` |
47 | 77 |
|
48 | 78 | Returns: |
49 | | - The server instance and a function for swapping out the view. |
| 79 | + The server instance and a function for swapping views. |
| 80 | + See :func:`idom.widgets.common.hotswap` for details. |
50 | 81 | """ |
51 | | - mount, element = hotswap(shared) |
| 82 | + mount, element = hotswap(shared=True) |
52 | 83 | server_instance = server(element) |
53 | 84 | if server_options: |
54 | 85 | server_instance.configure(server_options) |
55 | 86 | server_instance.daemon(host, port, **(run_options or {})) |
56 | | - return server_instance, mount |
| 87 | + return mount, server_instance |
0 commit comments