From 9434dd08e7fe11a2fc40416ad5a609cb2e1670fd Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Sun, 12 Nov 2017 15:43:27 +0200 Subject: [PATCH] Don't test for `nil` handler * it's already verified by the ring-router --- modules/reitit-ring/src/reitit/ring.cljc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/reitit-ring/src/reitit/ring.cljc b/modules/reitit-ring/src/reitit/ring.cljc index 8595380e..0ce495a0 100644 --- a/modules/reitit-ring/src/reitit/ring.cljc +++ b/modules/reitit-ring/src/reitit/ring.cljc @@ -14,7 +14,10 @@ [top (assoc childs k v)] [(assoc top k v) childs])) [{} {}] meta)) -(defn ring-handler [router] +(defn ring-handler + "Creates a ring-handler out of a ring-router. + Supports both 1 (sync) and 3 (async) arities." + [router] (with-meta (fn ([request] @@ -23,23 +26,20 @@ params (:params match) result (:result match) handler (or (-> result method :handler) - (-> result :any :handler))] - (if handler - (handler - (cond-> (impl/fast-assoc request ::match match) - (seq params) (impl/fast-assoc :path-params params))))))) + (-> result :any :handler)) + request (cond-> (impl/fast-assoc request ::match match) + (seq params) (impl/fast-assoc :path-params params))] + (handler request)))) ([request respond raise] (if-let [match (r/match-by-path router (:uri request))] (let [method (:request-method request :any) params (:params match) result (:result match) handler (or (-> result method :handler) - (-> result :any :handler))] - (if handler - (handler - (cond-> (impl/fast-assoc request ::match match) - (seq params) (impl/fast-assoc :path-params params)) - respond raise))) + (-> result :any :handler)) + request (cond-> (impl/fast-assoc request ::match match) + (seq params) (impl/fast-assoc :path-params params))] + (handler request respond raise)) (respond nil)))) {::router router}))