Create an event handler for the given function. Args: fn: The function to create an event handler for. event_handler_cls: The event handler class to use. Returns: The event handler.
(
cls, fn: Any, event_handler_cls: type[EventHandler] = EventHandler
)
| 1230 | |
| 1231 | @classmethod |
| 1232 | def _create_event_handler( |
| 1233 | cls, fn: Any, event_handler_cls: type[EventHandler] = EventHandler |
| 1234 | ): |
| 1235 | """Create an event handler for the given function. |
| 1236 | |
| 1237 | Args: |
| 1238 | fn: The function to create an event handler for. |
| 1239 | event_handler_cls: The event handler class to use. |
| 1240 | |
| 1241 | Returns: |
| 1242 | The event handler. |
| 1243 | """ |
| 1244 | from reflex_base.registry import RegistrationContext |
| 1245 | |
| 1246 | # Check if function has stored event_actions from decorator |
| 1247 | event_actions = getattr(fn, EVENT_ACTIONS_MARKER, {}) |
| 1248 | |
| 1249 | handler = event_handler_cls(fn=fn, state=cls, event_actions=event_actions) |
| 1250 | if cls.get_full_name() in all_base_state_classes: |
| 1251 | # Register handlers created after the class was registered. |
| 1252 | reg_ctx = RegistrationContext.get() |
| 1253 | reg_ctx.register_event_handler(handler, states=(cls,)) |
| 1254 | return handler |
| 1255 | |
| 1256 | @classmethod |
| 1257 | def _create_setvar(cls): |
no test coverage detected