|
1 | 1 | import abc |
2 | 2 | import asyncio |
3 | | -from types import coroutine |
4 | 3 | from typing import ( |
5 | 4 | List, |
6 | 5 | Dict, |
@@ -125,8 +124,11 @@ async def _create_layout_update(self, element: AbstractElement) -> LayoutUpdate: |
125 | 124 |
|
126 | 125 | async def _render_element(self, element_state: ElementState) -> Dict[str, Any]: |
127 | 126 | try: |
128 | | - # BUG: https://github.com/python/mypy/issues/9256 |
129 | | - raw_model = await _render_with_life_cycle_hook(element_state) # type: ignore |
| 127 | + element_state.life_cycle_hook.set_current() |
| 128 | + try: |
| 129 | + raw_model = await element_state.element_obj.render() |
| 130 | + finally: |
| 131 | + element_state.life_cycle_hook.unset_current() |
130 | 132 |
|
131 | 133 | if isinstance(raw_model, AbstractElement): |
132 | 134 | raw_model = {"tagName": "div", "children": [raw_model]} |
@@ -209,10 +211,6 @@ def _create_element_state( |
209 | 211 | life_cycle_hook=LifeCycleHook(element, self.update), |
210 | 212 | ) |
211 | 213 |
|
212 | | - def _reset_element_state(self, element_state: ElementState) -> None: |
213 | | - self._clear_element_state_event_handlers(element_state) |
214 | | - self._delete_element_state_children(element_state) |
215 | | - |
216 | 214 | def _delete_element_state(self, element_state: ElementState) -> None: |
217 | 215 | self._clear_element_state_event_handlers(element_state) |
218 | 216 | self._delete_element_state_children(element_state) |
@@ -252,26 +250,6 @@ def __repr__(self) -> str: |
252 | 250 | return f"{type(self).__name__}({self.root})" |
253 | 251 |
|
254 | 252 |
|
255 | | -@coroutine |
256 | | -def _render_with_life_cycle_hook(element_state: ElementState) -> Iterator[None]: |
257 | | - """Render an element which may use hooks. |
258 | | -
|
259 | | - We use a coroutine here because we need to know when control is yielded |
260 | | - back to the event loop since it might switch to render a different element. |
261 | | - """ |
262 | | - gen = element_state.element_obj.render().__await__() |
263 | | - try: |
264 | | - while True: |
265 | | - element_state.life_cycle_hook.set_current() |
266 | | - value = next(gen) |
267 | | - element_state.life_cycle_hook.unset_current() |
268 | | - yield value |
269 | | - except StopIteration as error: |
270 | | - return error.value |
271 | | - finally: |
272 | | - element_state.life_cycle_hook.unset_current() |
273 | | - |
274 | | - |
275 | 253 | class _ElementQueue: |
276 | 254 |
|
277 | 255 | __slots__ = "_queue", "_pending" |
|
0 commit comments