This commit is contained in:
Tommi Reiman 2017-12-09 23:46:26 +02:00
parent a2063587b1
commit 7af3f470d6
3 changed files with 10 additions and 18 deletions

View file

@ -116,7 +116,7 @@
(defn wild-route? [[path]]
(contains-wilds? path))
(defn conflicting-routes? [[p1 :as route1] [p2 :as route2]]
(defn conflicting-routes? [[p1] [p2]]
(loop [[s1 & ss1] (segments p1)
[s2 & ss2] (segments p2)]
(cond

View file

@ -9,7 +9,7 @@
(defrecord Middleware [name wrap])
(defrecord Endpoint [data handler middleware])
(defn create [{:keys [name wrap compile] :as m}]
(defn create [{:keys [wrap compile] :as m}]
(when (and wrap compile)
(throw
(ex-info

View file

@ -10,19 +10,19 @@
(extend-protocol Segment
nil
(-insert [this ps data])
(-lookup [this ps params]))
(-insert [_ _ _])
(-lookup [_ _ _]))
(defn- -catch-all [children catch-all data params p ps]
(defn- -catch-all [children catch-all params p ps]
(if catch-all
(-lookup
(impl/fast-get children catch-all)
nil
(assoc data :params (assoc params catch-all (str/join "/" (cons p ps)))))))
(assoc params catch-all (str/join "/" (cons p ps))))))
(defn- segment
([] (segment {} #{} nil nil))
([children wilds catch-all data]
([children wilds catch-all match]
(let [children' (impl/fast-map children)]
^{:type ::segment}
(reify
@ -34,13 +34,13 @@
wilds (if w (conj wilds w) wilds)
catch-all (or c catch-all)
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]
(if (nil? p)
(if data (assoc data :params params))
(if match (assoc match :params params))
(or (-lookup (impl/fast-get children' p) ps params)
(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]
(-insert (or root (segment)) (impl/segments path) (map->Match {:data data})))
@ -53,11 +53,3 @@
(defn lookup [segment path]
(-lookup segment (impl/segments path) {}))
(comment
(-> [["/:abba" 1]
["/:abba/:dabba" 2]
["/kikka/*kakka" 3]]
(create)
(lookup "/kikka/1/2")
(./aprint)))