mirror of
https://github.com/metosin/reitit.git
synced 2026-02-20 09:29:08 +00:00
inline lookup-structs
This commit is contained in:
parent
1a9792fd93
commit
9fc8710cad
1 changed files with 28 additions and 52 deletions
|
|
@ -165,23 +165,6 @@
|
||||||
:compile (fn [[_ {:keys [handler]}] _] handler)
|
:compile (fn [[_ {:keys [handler]}] _] handler)
|
||||||
:conflicts (partial throw-on-conflicts! path-conflicts-str)})
|
:conflicts (partial throw-on-conflicts! path-conflicts-str)})
|
||||||
|
|
||||||
(defn- linear-router-lookup-structs
|
|
||||||
"Returns a 2-item vec of lookup structures.
|
|
||||||
|
|
||||||
The first is a vec of Routes.
|
|
||||||
The second is a map of route names to lookup fns."
|
|
||||||
[compiled-routes]
|
|
||||||
(reduce
|
|
||||||
(fn [[pl nl] [p {:keys [name] :as data} result]]
|
|
||||||
(let [{:keys [path-params] :as route} (impl/create [p data result])
|
|
||||||
f #(if-let [path (impl/path-for route %)]
|
|
||||||
(->Match p data result % path)
|
|
||||||
(->PartialMatch p data result % path-params))]
|
|
||||||
[(conj pl route)
|
|
||||||
(if name (assoc nl name f) nl)]))
|
|
||||||
[[] {}]
|
|
||||||
compiled-routes))
|
|
||||||
|
|
||||||
(defn linear-router
|
(defn linear-router
|
||||||
"Creates a linear-router from resolved routes and optional
|
"Creates a linear-router from resolved routes and optional
|
||||||
expanded options. See [[router]] for available options"
|
expanded options. See [[router]] for available options"
|
||||||
|
|
@ -189,7 +172,16 @@
|
||||||
(linear-router compiled-routes {}))
|
(linear-router compiled-routes {}))
|
||||||
([compiled-routes opts]
|
([compiled-routes opts]
|
||||||
(let [names (find-names compiled-routes opts)
|
(let [names (find-names compiled-routes opts)
|
||||||
[pl nl] (linear-router-lookup-structs compiled-routes)
|
[pl nl] (reduce
|
||||||
|
(fn [[pl nl] [p {:keys [name] :as data} result]]
|
||||||
|
(let [{:keys [path-params] :as route} (impl/create [p data result])
|
||||||
|
f #(if-let [path (impl/path-for route %)]
|
||||||
|
(->Match p data result % path)
|
||||||
|
(->PartialMatch p data result % path-params))]
|
||||||
|
[(conj pl route)
|
||||||
|
(if name (assoc nl name f) nl)]))
|
||||||
|
[[] {}]
|
||||||
|
compiled-routes)
|
||||||
lookup (impl/fast-map nl)
|
lookup (impl/fast-map nl)
|
||||||
routes (uncompile-routes compiled-routes)]
|
routes (uncompile-routes compiled-routes)]
|
||||||
^{:type ::router}
|
^{:type ::router}
|
||||||
|
|
@ -218,21 +210,6 @@
|
||||||
(if-let [match (impl/fast-get lookup name)]
|
(if-let [match (impl/fast-get lookup name)]
|
||||||
(match (impl/path-params path-params))))))))
|
(match (impl/path-params path-params))))))))
|
||||||
|
|
||||||
(defn- lookup-router-lookup-structs
|
|
||||||
"Returns a 2-item vec of lookup structures.
|
|
||||||
|
|
||||||
The first is a map of paths to Matches.
|
|
||||||
The second is a map of route names to Matches."
|
|
||||||
[compiled-routes]
|
|
||||||
(reduce
|
|
||||||
(fn [[pl nl] [p {:keys [name] :as data} result]]
|
|
||||||
[(assoc pl p (->Match p data result {} p))
|
|
||||||
(if name
|
|
||||||
(assoc nl name #(->Match p data result % p))
|
|
||||||
nl)])
|
|
||||||
[{} {}]
|
|
||||||
compiled-routes))
|
|
||||||
|
|
||||||
(defn lookup-router
|
(defn lookup-router
|
||||||
"Creates a lookup-router from resolved routes and optional
|
"Creates a lookup-router from resolved routes and optional
|
||||||
expanded options. See [[router]] for available options"
|
expanded options. See [[router]] for available options"
|
||||||
|
|
@ -246,7 +223,14 @@
|
||||||
{:wilds wilds
|
{:wilds wilds
|
||||||
:routes compiled-routes})))
|
:routes compiled-routes})))
|
||||||
(let [names (find-names compiled-routes opts)
|
(let [names (find-names compiled-routes opts)
|
||||||
[pl nl] (lookup-router-lookup-structs compiled-routes)
|
[pl nl] (reduce
|
||||||
|
(fn [[pl nl] [p {:keys [name] :as data} result]]
|
||||||
|
[(assoc pl p (->Match p data result {} p))
|
||||||
|
(if name
|
||||||
|
(assoc nl name #(->Match p data result % p))
|
||||||
|
nl)])
|
||||||
|
[{} {}]
|
||||||
|
compiled-routes)
|
||||||
data (impl/fast-map pl)
|
data (impl/fast-map pl)
|
||||||
lookup (impl/fast-map nl)
|
lookup (impl/fast-map nl)
|
||||||
routes (uncompile-routes compiled-routes)]
|
routes (uncompile-routes compiled-routes)]
|
||||||
|
|
@ -271,23 +255,6 @@
|
||||||
(if-let [match (impl/fast-get lookup name)]
|
(if-let [match (impl/fast-get lookup name)]
|
||||||
(match (impl/path-params path-params))))))))
|
(match (impl/path-params path-params))))))))
|
||||||
|
|
||||||
(defn- segment-router-lookup-structs
|
|
||||||
"Returns a 2-item vec of lookup structures.
|
|
||||||
|
|
||||||
The first is a prefix-tree of segments and associated Matches.
|
|
||||||
The second is a map of route names to Matches or PartialMatches."
|
|
||||||
[compiled-routes]
|
|
||||||
(reduce
|
|
||||||
(fn [[pl nl] [p {:keys [name] :as data} result]]
|
|
||||||
(let [{:keys [path-params] :as route} (impl/create [p data result])
|
|
||||||
f #(if-let [path (impl/path-for route %)]
|
|
||||||
(->Match p data result % path)
|
|
||||||
(->PartialMatch p data result % path-params))]
|
|
||||||
[(segment/insert pl p (->Match p data result nil nil))
|
|
||||||
(if name (assoc nl name f) nl)]))
|
|
||||||
[nil {}]
|
|
||||||
compiled-routes))
|
|
||||||
|
|
||||||
(defn segment-router
|
(defn segment-router
|
||||||
"Creates a special prefix-tree style segment router from resolved routes and optional
|
"Creates a special prefix-tree style segment router from resolved routes and optional
|
||||||
expanded options. See [[router]] for available options"
|
expanded options. See [[router]] for available options"
|
||||||
|
|
@ -295,7 +262,16 @@
|
||||||
(segment-router compiled-routes {}))
|
(segment-router compiled-routes {}))
|
||||||
([compiled-routes opts]
|
([compiled-routes opts]
|
||||||
(let [names (find-names compiled-routes opts)
|
(let [names (find-names compiled-routes opts)
|
||||||
[pl nl] (segment-router-lookup-structs compiled-routes)
|
[pl nl] (reduce
|
||||||
|
(fn [[pl nl] [p {:keys [name] :as data} result]]
|
||||||
|
(let [{:keys [path-params] :as route} (impl/create [p data result])
|
||||||
|
f #(if-let [path (impl/path-for route %)]
|
||||||
|
(->Match p data result % path)
|
||||||
|
(->PartialMatch p data result % path-params))]
|
||||||
|
[(segment/insert pl p (->Match p data result nil nil))
|
||||||
|
(if name (assoc nl name f) nl)]))
|
||||||
|
[nil {}]
|
||||||
|
compiled-routes)
|
||||||
lookup (impl/fast-map nl)
|
lookup (impl/fast-map nl)
|
||||||
routes (uncompile-routes compiled-routes)]
|
routes (uncompile-routes compiled-routes)]
|
||||||
^{:type ::router}
|
^{:type ::router}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue