mirror of
https://github.com/metosin/reitit.git
synced 2026-02-12 22:35:19 +00:00
Cleanup
This commit is contained in:
parent
a2063587b1
commit
7af3f470d6
3 changed files with 10 additions and 18 deletions
|
|
@ -116,7 +116,7 @@
|
||||||
(defn wild-route? [[path]]
|
(defn wild-route? [[path]]
|
||||||
(contains-wilds? path))
|
(contains-wilds? path))
|
||||||
|
|
||||||
(defn conflicting-routes? [[p1 :as route1] [p2 :as route2]]
|
(defn conflicting-routes? [[p1] [p2]]
|
||||||
(loop [[s1 & ss1] (segments p1)
|
(loop [[s1 & ss1] (segments p1)
|
||||||
[s2 & ss2] (segments p2)]
|
[s2 & ss2] (segments p2)]
|
||||||
(cond
|
(cond
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
(defrecord Middleware [name wrap])
|
(defrecord Middleware [name wrap])
|
||||||
(defrecord Endpoint [data handler middleware])
|
(defrecord Endpoint [data handler middleware])
|
||||||
|
|
||||||
(defn create [{:keys [name wrap compile] :as m}]
|
(defn create [{:keys [wrap compile] :as m}]
|
||||||
(when (and wrap compile)
|
(when (and wrap compile)
|
||||||
(throw
|
(throw
|
||||||
(ex-info
|
(ex-info
|
||||||
|
|
|
||||||
|
|
@ -10,19 +10,19 @@
|
||||||
|
|
||||||
(extend-protocol Segment
|
(extend-protocol Segment
|
||||||
nil
|
nil
|
||||||
(-insert [this ps data])
|
(-insert [_ _ _])
|
||||||
(-lookup [this ps params]))
|
(-lookup [_ _ _]))
|
||||||
|
|
||||||
(defn- -catch-all [children catch-all data params p ps]
|
(defn- -catch-all [children catch-all params p ps]
|
||||||
(if catch-all
|
(if catch-all
|
||||||
(-lookup
|
(-lookup
|
||||||
(impl/fast-get children catch-all)
|
(impl/fast-get children catch-all)
|
||||||
nil
|
nil
|
||||||
(assoc data :params (assoc params catch-all (str/join "/" (cons p ps)))))))
|
(assoc params catch-all (str/join "/" (cons p ps))))))
|
||||||
|
|
||||||
(defn- segment
|
(defn- segment
|
||||||
([] (segment {} #{} nil nil))
|
([] (segment {} #{} nil nil))
|
||||||
([children wilds catch-all data]
|
([children wilds catch-all match]
|
||||||
(let [children' (impl/fast-map children)]
|
(let [children' (impl/fast-map children)]
|
||||||
^{:type ::segment}
|
^{:type ::segment}
|
||||||
(reify
|
(reify
|
||||||
|
|
@ -34,13 +34,13 @@
|
||||||
wilds (if w (conj wilds w) wilds)
|
wilds (if w (conj wilds w) wilds)
|
||||||
catch-all (or c catch-all)
|
catch-all (or c catch-all)
|
||||||
children (update children (or w c p) #(-insert (or % (segment)) ps d))]
|
children (update children (or w c p) #(-insert (or % (segment)) ps d))]
|
||||||
(segment children wilds catch-all data))))
|
(segment children wilds catch-all match))))
|
||||||
(-lookup [_ [p & ps] params]
|
(-lookup [_ [p & ps] params]
|
||||||
(if (nil? p)
|
(if (nil? p)
|
||||||
(if data (assoc data :params params))
|
(if match (assoc match :params params))
|
||||||
(or (-lookup (impl/fast-get children' p) ps params)
|
(or (-lookup (impl/fast-get children' p) ps params)
|
||||||
(some #(-lookup (impl/fast-get children' %) ps (assoc params % p)) wilds)
|
(some #(-lookup (impl/fast-get children' %) ps (assoc params % p)) wilds)
|
||||||
(-catch-all children' catch-all data params p ps))))))))
|
(-catch-all children' catch-all params p ps))))))))
|
||||||
|
|
||||||
(defn insert [root path data]
|
(defn insert [root path data]
|
||||||
(-insert (or root (segment)) (impl/segments path) (map->Match {:data data})))
|
(-insert (or root (segment)) (impl/segments path) (map->Match {:data data})))
|
||||||
|
|
@ -53,11 +53,3 @@
|
||||||
|
|
||||||
(defn lookup [segment path]
|
(defn lookup [segment path]
|
||||||
(-lookup segment (impl/segments path) {}))
|
(-lookup segment (impl/segments path) {}))
|
||||||
|
|
||||||
(comment
|
|
||||||
(-> [["/:abba" 1]
|
|
||||||
["/:abba/:dabba" 2]
|
|
||||||
["/kikka/*kakka" 3]]
|
|
||||||
(create)
|
|
||||||
(lookup "/kikka/1/2")
|
|
||||||
(./aprint)))
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue