Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add route information to request. #140
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.