-
Notifications
You must be signed in to change notification settings - Fork 183
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 global event bus #1051
Add global event bus #1051
Conversation
6216943
to
adf4836
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the direction!
The changes look functionally good, but I'd like to chat before approving.
About the multiple buses scenario -- I can't really imagine a use case, would events get published to all of them or just some of them (if some of them, how would the publisher decide which)? If you just want to listen to a subset of events, the event listener should be able to filter out events it doesn't care about.
@dylanholmes what do you think about dropping the |
50caaec
to
0f19385
Compare
class EventPublisherMixin: | ||
event_listeners: list[EventListener] = field(factory=list, kw_only=True) | ||
class _EventBus: | ||
_event_listeners: list[EventListener] = field(factory=list, kw_only=True, alias="_event_listeners") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is uglier than just not using attrs imo. Plus it still adds _event_listeners
as an keyword arg in init
.
I don't care that much though
Not sure, I kind of like This seems like a good opportunity to mention another "syntax golfing" idea I had that I wasn't going to share publicly. Accept the event_bus.add_event_listener(my_callback, event_types=[...]) |
c391b14
to
863bcde
Compare
Let's just leave it as is.
I like the conciseness, but I'd rather introduce even more breaking changes at this point. Let's evaluate in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
Just one optional suggestion
event_bus.add_event_listeners( | ||
[ | ||
EventListener( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be plural? Can there be a singular add_event_listener
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not _need_to be plural, no. Let's just leave it as is, docs will get an overhaul at some point soon.
Describe your changes
Added
griptape.events.EventBus
, for publishing and subscribing to events.Changed
EventPublisherMixin
in favor ofEventBus
.EventPublisherMixin
.A couple things I'm unsure about:
logging
module? Something like:I can't think of any scenario where you'd want multiple busses, especially since you can pass in many
EventListeners
.2. If we stick with a singleton, does the PascalCase naming of the variable make sense? The idea was that it might convey the global nature of it, similar to how you might access static fields.
Issue ticket number and link
NA
📚 Documentation preview 📚: https://griptape--1051.org.readthedocs.build//1051/