Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "Listener" interface to Events API #16003

Open
Zsailer opened this issue Mar 15, 2024 · 0 comments
Open

Add a "Listener" interface to Events API #16003

Zsailer opened this issue Mar 15, 2024 · 0 comments

Comments

@Zsailer
Copy link
Member

Zsailer commented Mar 15, 2024

Problem

The server-side event system includes an API for registering "listeners"—callbacks attached to specific events schema IDs—to the EventLogger in Python.

I'd like to mirror this API in JupyterLab's EventManager to make it easier to register callbacks to the Stream interface.

Currently, the pattern for listening to events is to connect a callback to the Stream signal. Adding multiple listeners requires either 1) multiple connections to a signal that check the income event's ID to see if you should fire your callback, or 2) make one connection to the stream signal and maintain your own hashtable for listener lookup. I find myself doing (2) for each plugin I create that listens to events. I think offering a single API—like we did in the server—in JupyterLab core would make it easier for folks to hook into the event stream.

Proposed Solution

Add a addListener and removeListener APIs to the EventManager.

The EventManager would maintain a map of {schemaID: set(listeners)}, offering a hash table to easily fire listener methods attached to specific event types.

Instead of folks adding their own connections to the Stream signal, they could just add listeners using this API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants