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

Event dispatch improvements #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

tech6hutch
Copy link

@tech6hutch tech6hutch commented Feb 21, 2018

Changed dispatch to be more efficient, readable, and idiomatic. Also fixed a cache retrieval bug in dispatch.

Note: this hasn't been tested yet.

@tech6hutch
Copy link
Author

Oh, this might not fit your style guidelines. I can fix it tomorrow.

Copy link
Owner

@tripl3dogdare tripl3dogdare left a 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.

(:require
[disclojure.gateway :as gw]
[disclojure.cache :as cache]))
(:require [clojure.string :as str]
Copy link
Owner

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.

Copy link
Author

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.

(= (% :event) :any)
(= (or (-> % :event event-aliases) (% :event)) event-name))
(@client :listeners))]
(when (pos? (count listeners))
Copy link
Owner

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.

Copy link
Author

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.

Copy link
Owner

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?

Copy link
Author

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.

Copy link
Owner

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.

@tech6hutch
Copy link
Author

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 disclojure.util?

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

Successfully merging this pull request may close these issues.

2 participants