-
Notifications
You must be signed in to change notification settings - Fork 1
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
Event dispatch improvements #1
base: master
Are you sure you want to change the base?
Conversation
Oh, this might not fit your style guidelines. I can fix it tomorrow. |
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.
Good work, but I have a couple questions/notes - see my inline comments.
src/disclojure/core.clj
Outdated
(:require | ||
[disclojure.gateway :as gw] | ||
[disclojure.cache :as cache])) | ||
(:require [clojure.string :as str] |
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.
Generally speaking, I prefer using the existing Java methods over adding an extra import when it comes to string manipulation. Nothing particularly wrong with it, but it's a bit more concise and doesn't hurt readability IMO.
Being idiomatic is great, but if it's only being used in internal code (for example, string manipulation inside the dispatch method) as opposed to being something exposed to potential callers (for example, the dispatch method itself), I'm more concerned with conciseness and readability than with being idiomatic. If there's a distinct benefit beyond personal opinion (performance, a significant difference in LOC, etc.), then feel free to let me know - otherwise, I'd prefer to avoid these sorts of changes.
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.
Makes sense. I'm not aware of any other benefit, no, so...Java interop it is.
src/disclojure/core.clj
Outdated
(= (% :event) :any) | ||
(= (or (-> % :event event-aliases) (% :event)) event-name)) | ||
(@client :listeners))] | ||
(when (pos? (count 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.
Not really sure what this line is for... What does it add to the process that was missing before? Especially considering it forces the extra let
statement on the next line.
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.
My reasoning was that if there are no listeners for this event, might as well avoid the extra work of accessing the cache, struct creation, etc.
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.
Ah, okay. Is there a way we can short-circuit that without splitting the let
in two?
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.
Hm. Could do an if
for every definition after that. That's all I can think of.
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.
Blech... I'll take a look at it when I have a few minutes, see if there's anything to be done there.
Backported from my event-rewrite branch.
I should mention, with this latest commit, one of the new functions I added I made public, since I feel like it could have use to users. Perhaps this would be more suitable to a new file and ns for utility functions; perhaps a |
Changed
dispatch
to be more efficient, readable, and idiomatic. Also fixed a cache retrieval bug indispatch
.Note: this hasn't been tested yet.