Make a :data:`~reactpy.core.proto.EventHandlerFunc` from a function or coroutine Parameters: function: A function or coroutine accepting a number of positional arguments. positional_args: Whether to pass the event parameters a positional args or as a list
(
function: Callable[..., Any],
positional_args: bool = True,
)
| 129 | |
| 130 | |
| 131 | def to_event_handler_function( |
| 132 | function: Callable[..., Any], |
| 133 | positional_args: bool = True, |
| 134 | ) -> EventHandlerFunc: |
| 135 | """Make a :data:`~reactpy.core.proto.EventHandlerFunc` from a function or coroutine |
| 136 | |
| 137 | Parameters: |
| 138 | function: |
| 139 | A function or coroutine accepting a number of positional arguments. |
| 140 | positional_args: |
| 141 | Whether to pass the event parameters a positional args or as a list. |
| 142 | """ |
| 143 | if positional_args: |
| 144 | if asyncio.iscoroutinefunction(function): |
| 145 | |
| 146 | async def wrapper(data: Sequence[Any]) -> None: |
| 147 | await function(*data) |
| 148 | |
| 149 | else: |
| 150 | |
| 151 | async def wrapper(data: Sequence[Any]) -> None: |
| 152 | function(*data) |
| 153 | |
| 154 | return wrapper |
| 155 | elif not asyncio.iscoroutinefunction(function): |
| 156 | |
| 157 | async def wrapper(data: Sequence[Any]) -> None: |
| 158 | function(data) |
| 159 | |
| 160 | return wrapper |
| 161 | else: |
| 162 | return function |
| 163 | |
| 164 | |
| 165 | def merge_event_handlers( |
no outgoing calls