Get an `Event` instance for the specified event name. Event names must start with `on_` (e.g. `on_click`). Creates and caches `Event` instances that are triggered when the DOM event fires.
(self, name)
| 566 | return name |
| 567 | |
| 568 | def get_event(self, name): |
| 569 | """ |
| 570 | Get an `Event` instance for the specified event name. |
| 571 | |
| 572 | Event names must start with `on_` (e.g. `on_click`). Creates and |
| 573 | caches `Event` instances that are triggered when the DOM event fires. |
| 574 | """ |
| 575 | if not name.startswith("on_"): |
| 576 | raise ValueError("Event names must start with 'on_'.") |
| 577 | event_name = name[3:] # Remove 'on_' prefix. |
| 578 | if not hasattr(self._dom_element, event_name): |
| 579 | raise ValueError(f"Element has no '{event_name}' event.") |
| 580 | if name in self._on_events: |
| 581 | return self._on_events[name] |
| 582 | # Create Event instance and wire it to the DOM event. |
| 583 | ev = Event() |
| 584 | self._on_events[name] = ev |
| 585 | self._dom_element.addEventListener(event_name, create_proxy(ev.trigger)) |
| 586 | return ev |
| 587 | |
| 588 | @property |
| 589 | def children(self): |