()
| 197 | |
| 198 | @component |
| 199 | def HotSwap() -> Any: |
| 200 | # new displays will adopt the latest constructor and arguments |
| 201 | constructor, _set_constructor = use_state(lambda: constructor_ref.current) |
| 202 | set_constructor = use_callback(lambda new: _set_constructor(lambda _: new)) |
| 203 | |
| 204 | def add_callback() -> Callable[[], None]: |
| 205 | set_constructor_callbacks.add(set_constructor) |
| 206 | return lambda: set_constructor_callbacks.remove(set_constructor) |
| 207 | |
| 208 | use_effect(add_callback) |
| 209 | |
| 210 | return constructor() |
| 211 | |
| 212 | def swap(constructor: Callable[[], Any] | None) -> None: |
| 213 | constructor = constructor_ref.current = constructor or (lambda: None) |
nothing calls this directly
no test coverage detected