-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Zsailer/listener
Add Listeners API
- Loading branch information
Showing
6 changed files
with
371 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ defining-schema | |
configure | ||
application | ||
modifiers | ||
listeners | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Adding event listeners | ||
|
||
Event listeners are callback functions/methods that are executed when an event is emitted. | ||
|
||
Listeners can be used by extension authors to trigger custom logic every time an event occurs. | ||
|
||
## Basic usage | ||
|
||
Define a listener function: | ||
|
||
```python | ||
from jupyter_events.logger import EventLogger | ||
|
||
def my_listener(logger: EventLogger, schema_id: str, data: dict) -> None: | ||
print("hello, from my listener") | ||
``` | ||
|
||
Hook this listener to a specific event type: | ||
|
||
```python | ||
event_logger.add_listener("http://event.jupyter.org/my-event", listener=my_listener) | ||
``` | ||
|
||
Now, every time a `"http://event.jupyter.org/test"` event is emitted from the EventLogger, this listener will be called. |
Oops, something went wrong.