-
Notifications
You must be signed in to change notification settings - Fork 258
Add route information to request. #140
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
Conversation
@@ -102,6 +102,12 @@ | |||
((mw handler) request) | |||
(handler request)))) | |||
|
|||
(defn- add-route-information |
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.
assoc-route-info
would be a name more in keeping with the other functions in the namespace.
Couple of questions: Is the reason you say to precompute the route info to decouple the add-route-information function from needing to know about the stuff? Secondly, after doing that and renaming the add-route-information to assoc-route-info, it doesn't seem like there's much added to having that private fn so I removed it. Is that cool? Thanks for your feedback! |
Precomputation just avoids creating a new vector each time. So currently you've written: (defn make-route [method path handler]
(if-method method
(if-route path
(wrap-route-middleware
(fn [request]
(let [route-info [(or method :any) (str path)]]
(response/render (handler (assoc request :route route-info))
request))))))) But we can take the (defn make-route [method path handler]
(let [route-info [(or method :any) (str path)]]
(if-method method
(if-route path
(wrap-route-middleware
(fn [request]
(let [request (assoc request :route route-info)]
(response/render (handler request) request)))))))) Now the route-info vector is only calculated once, when the route is first constructed. Even though building the route-info isn't likely to take long, if we can save a little time and memory just by moving the let binding around, we should do it. |
Removing the private function was the right call, I think. Could you also add a test to check that |
Ping @weavejester |
Thanks for the ping. This should be okay, but I think that |
@weavejester good? |
That looks fine. Now you just need to squash your commits. |
Squashed. |
Thanks! Can you remove the ending "." from the commit summary? Then I'll merge. |
Done! |
Add route information to request
Feature for #82 and subsumes #93