From 824b672513c6476fa8dbc469a64d81ab143325c0 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Mon, 13 Jan 2020 21:26:49 +0200 Subject: [PATCH] Update observer docs --- docs/dispatcher/observer.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/dispatcher/observer.md b/docs/dispatcher/observer.md index 222503e9..b98db9b6 100644 --- a/docs/dispatcher/observer.md +++ b/docs/dispatcher/observer.md @@ -14,12 +14,11 @@ Reference: `#!python3 aiogram.dispatcher.event.observer.EventObserver` That is base observer for all events. ### Base registering method -Method: `.register(callback, filter1, filter2, ...)` +Method: `.register()` | Argument | Type | Description | | --- | --- | --- | | `callback` | `#!python3 Callable[[Any], Awaitable[Any]]` | Event handler | -| `*filters` | `#!python3 Union[Callable[[Any], Any], Callable[[Any], Awaitable[Any]], BaseFilter]` | Ordered filters set | Will return original callback. @@ -28,14 +27,15 @@ Will return original callback. Usage: ```python3 -@(filter1, filter2, ...) +@() async def handler(*args, **kwargs): pass ``` ## TelegramEventObserver Is subclass of [EventObserver](#eventobserver) with some differences. -In this handler can be bounded filters which can be used as keyword arguments instead of writing full references when you register new handlers. +Here you can register handler with filters or bounded filters which can be used as keyword arguments instead of writing full references when you register new handlers. +This observer will stops event propagation when first handler is pass. ### Registering bound filters @@ -44,7 +44,7 @@ Bound filter should be subclass of [BaseFilter](filters/index.md) `#!python3 .bind_filter(MyFilter)` ### Registering handlers -Method: `EventObserver.register(callback, filter1, filter2, ..., bound_filter=value, ...)` +Method: `TelegramEventObserver.register(callback, filter1, filter2, ..., bound_filter=value, ...)` In this method is added bound filters keywords interface. | Argument | Type | Description | @@ -52,3 +52,13 @@ In this method is added bound filters keywords interface. | `callback` | `#!python3 Callable[[Any], Awaitable[Any]]` | Event handler | | `*filters` | `#!python3 Union[Callable[[Any], Any], Callable[[Any], Awaitable[Any]], BaseFilter]` | Ordered filters set | | `**bound_filters` | `#!python3 Any` | Bound filters | + + +### Decorator-style registering event handler with filters + +Usage: +```python3 +@(filter1, filter2, ...) +async def handler(*args, **kwargs): + pass +```