Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5091501

Browse filesBrowse files
authored
make Layout context management async (#730)
* make Layout context management async * fix LayoutType * changelog entry
1 parent fc8ff68 commit 5091501
Copy full SHA for 5091501

File tree

7 files changed

+85
-84
lines changed
Filter options

7 files changed

+85
-84
lines changed

‎docs/source/about/changelog.rst

Copy file name to clipboardExpand all lines: docs/source/about/changelog.rst
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ more info, see the :ref:`Contributor Guide <Creating a Changelog Entry>`.
2323
Unreleased
2424
----------
2525

26-
Nothing yet...
26+
Changed:
27+
28+
- :pull:`730` - Layout context management is not async
2729

2830

2931
0.38.0-a2
@@ -444,7 +446,7 @@ See :ref:`Custom JavaScript Components` for details on the new interface.
444446
- Make docs section margins larger - :issue:`450`
445447
- Search broken in docs - :issue:`443`
446448
- Move src/idom/client out of Python package - :issue:`429`
447-
- Use composition instead of classes with Layout and LifeCycleHook - :issue:`412`
449+
- Use composition instead of classes async with Layout and LifeCycleHook - :issue:`412`
448450
- Remove Python language extension - :issue:`282`
449451
- Add keys to models so React doesn't complain of child arrays requiring them -
450452
:issue:`255`

‎docs/source/about/contributor-guide.rst

Copy file name to clipboardExpand all lines: docs/source/about/contributor-guide.rst
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ might look like:
9292
9393
**Added**
9494
95-
- A really cool new feature - :pull:`123`
95+
- :pull:`123` - A really cool new feature
9696
9797
**Changed**
9898
99-
- The behavior of some existing feature - :pull:`456`
99+
- :pull:`456` - The behavior of some existing feature
100100
101101
**Fixed**
102102
103-
- Some really bad bug - :issue:`789`
103+
- :issue:`789` - Some really bad bug
104104
105105
.. note::
106106

‎src/idom/core/layout.py

Copy file name to clipboardExpand all lines: src/idom/core/layout.py
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ class LayoutEvent(NamedTuple):
6161
"""A list of event data passed to the event handler."""
6262

6363

64-
_Self = TypeVar("_Self", bound="Layout")
65-
66-
6764
class Layout:
6865
"""Responsible for "rendering" components. That is, turning them into VDOM."""
6966

@@ -84,7 +81,7 @@ def __init__(self, root: "ComponentType") -> None:
8481
raise TypeError(f"Expected a ComponentType, not {type(root)!r}.")
8582
self.root = root
8683

87-
def __enter__(self: _Self) -> _Self:
84+
async def __aenter__(self) -> Layout:
8885
# create attributes here to avoid access before entering context manager
8986
self._event_handlers: EventHandlerDict = {}
9087

@@ -98,7 +95,7 @@ def __enter__(self: _Self) -> _Self:
9895

9996
return self
10097

101-
def __exit__(self, *exc: Any) -> None:
98+
async def __aexit__(self, *exc: Any) -> None:
10299
root_csid = self._root_life_cycle_state_id
103100
root_model_state = self._model_states_by_life_cycle_state_id[root_csid]
104101
self._unmount_model_states([root_model_state])

‎src/idom/core/serve.py

Copy file name to clipboardExpand all lines: src/idom/core/serve.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def serve_json_patch(
3939
recv: RecvCoroutine,
4040
) -> None:
4141
"""Run a dispatch loop for a single view instance"""
42-
with layout:
42+
async with layout:
4343
try:
4444
async with create_task_group() as task_group:
4545
task_group.start_soon(_single_outgoing_loop, layout, send)

‎src/idom/core/types.py

Copy file name to clipboardExpand all lines: src/idom/core/types.py
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def should_render(self: _OwnType, new: _OwnType) -> bool:
5151
"""Whether the new component instance should be rendered."""
5252

5353

54-
_Self = TypeVar("_Self")
5554
_Render = TypeVar("_Render", covariant=True)
5655
_Event = TypeVar("_Event", contravariant=True)
5756

@@ -66,11 +65,14 @@ async def render(self) -> _Render:
6665
async def deliver(self, event: _Event) -> None:
6766
"""Relay an event to its respective handler"""
6867

69-
def __enter__(self: _Self) -> _Self:
68+
async def __aenter__(self) -> LayoutType[_Render, _Event]:
7069
"""Prepare the layout for its first render"""
7170

72-
def __exit__(
73-
self, exc_type: Type[Exception], exc_value: Exception, traceback: TracebackType
71+
async def __aexit__(
72+
self,
73+
exc_type: Type[Exception],
74+
exc_value: Exception,
75+
traceback: TracebackType,
7476
) -> Optional[bool]:
7577
"""Clean up the view after its final render"""
7678

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.