From 5d30a73badf4b1250471ba930371b34f35467ff7 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Fri, 15 Mar 2024 09:21:51 +0200 Subject: [PATCH] feat: reitit.core/Expand for Vars --- modules/reitit-core/src/reitit/core.cljc | 4 ++++ test/cljc/reitit/core_test.cljc | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/reitit-core/src/reitit/core.cljc b/modules/reitit-core/src/reitit/core.cljc index 0b32fd73..40dac3f4 100644 --- a/modules/reitit-core/src/reitit/core.cljc +++ b/modules/reitit-core/src/reitit/core.cljc @@ -28,6 +28,10 @@ :cljs function) (expand [this _] {:handler this}) + #?(:clj clojure.lang.Var + :cljs cljs.core.Var) + (expand [this _] {:handler this}) + nil (expand [_ _])) diff --git a/test/cljc/reitit/core_test.cljc b/test/cljc/reitit/core_test.cljc index fc112239..98980546 100644 --- a/test/cljc/reitit/core_test.cljc +++ b/test/cljc/reitit/core_test.cljc @@ -6,6 +6,9 @@ (:import (clojure.lang ExceptionInfo) (reitit.core Router)))) +(defn- var-handler [& _] + "var-handler") + (deftest reitit-test (testing "routers handling wildcard paths" @@ -245,7 +248,11 @@ (let [router (r/router ["/ping" (constantly "ok")]) {:keys [result]} (r/match-by-path router "/ping")] (is result) - (is (= "ok" (result)))))) + (is (= "ok" (result)))) + (testing "var handler gets expanded" + (let [router (r/router ["/ping" #'var-handler]) + {:keys [result]} (r/match-by-path router "/ping")] + (is (= #'var-handler result)))))) (testing "custom router" (let [router (r/router ["/ping"] {:router (fn [_ _]