def on(selector: str, event: str, filter_selector: str=None, throttle=False, stop_propagation=False):
"""Register a coroutine function as a handler for the given event.
Corresponding to `$(selector).on(event, filter_selector, ...)` in jQuery
Args:
selector: A jQuery selector expression
event: One or more space-separated event types and optional namespaces, such as "click".
filter_selector: a selector string to filter the descendants of the selected elements that trigger the event.
If this argument is omitted, the event is always triggered when it reaches the selected element.
throttle: Whether to discard events when Portkey is busy.
Should set to true if the event is going to fire at very high frequency.
If set to false, all events will be queued and handled.
stop_propagation: Prevents the event from bubbling up the DOM tree,
preventing any parent handlers from being notified of the event.
Returns: A decorator that returns the original function.
"""
def decorator(func):
assert inspect.iscoroutinefunction(func), \
'Only a coroutine function (a function defined with an async def syntax)' \
' can be registered as an event handler.'
handler_info = get_handler_info(func)
# assert handler_info.handler is None, \
# 'You should only register one event on a handler function.'
handler_info._handler = func
handler_info.handler = id(func)
handler_info.selector = selector
handler_info.event = event
handler_info.filter_selector = filter_selector
handler_info.throttle = throttle
handler_info.stop_propagation = stop_propagation
return func
return decorator
评论列表
文章目录