mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
Welcome Interceptor registry!
This commit is contained in:
parent
94431352b8
commit
6c47b5fa94
2 changed files with 24 additions and 0 deletions
|
|
@ -13,6 +13,17 @@
|
|||
|
||||
(extend-protocol IntoInterceptor
|
||||
|
||||
#?(:clj clojure.lang.Keyword
|
||||
:cljs cljs.core.Keyword)
|
||||
(into-interceptor [this data {:keys [::registry] :as opts}]
|
||||
(or (if-let [interceptor (if registry (registry this))]
|
||||
(into-interceptor interceptor data opts))
|
||||
(throw
|
||||
(ex-info
|
||||
(str "Interceptor " (pr-str this) " not found in registry.")
|
||||
{:keyword this
|
||||
:registry registry}))))
|
||||
|
||||
#?(:clj clojure.lang.APersistentVector
|
||||
:cljs cljs.core.PersistentVector)
|
||||
(into-interceptor [[f & args :as form] data opts]
|
||||
|
|
|
|||
|
|
@ -58,6 +58,19 @@
|
|||
(is (= [:value :ok] (app ctx)))
|
||||
(is (= 1 @calls)))))
|
||||
|
||||
(testing "as keyword"
|
||||
(reset! calls 0)
|
||||
(let [app (create [:enter] {::interceptor/registry {:enter (enter :value)}})]
|
||||
(dotimes [_ 10]
|
||||
(is (= [:value :ok] (app ctx)))
|
||||
(is (= 1 @calls)))))
|
||||
|
||||
(testing "missing keyword"
|
||||
(is (thrown-with-msg?
|
||||
ExceptionInfo
|
||||
#"Interceptor :enter not found in registry"
|
||||
(create [:enter]))))
|
||||
|
||||
(testing "as map"
|
||||
(reset! calls 0)
|
||||
(let [app (create [{:enter (enter :value)}])]
|
||||
|
|
|
|||
Loading…
Reference in a new issue