mirror of
https://github.com/metosin/reitit.git
synced 2026-01-28 17:00:34 +00:00
Cleanup code
This commit is contained in:
parent
e6beae52f0
commit
3d4737b3fb
1 changed files with 12 additions and 19 deletions
|
|
@ -38,18 +38,14 @@
|
||||||
([routes]
|
([routes]
|
||||||
(walk ["" []] routes))
|
(walk ["" []] routes))
|
||||||
([[pacc macc] routes]
|
([[pacc macc] routes]
|
||||||
(let [subwalk (fn [path meta routes]
|
(letfn [(subwalk [p m r]
|
||||||
(reduce
|
(reduce #(into %1 (walk [p m] %2)) [] r))]
|
||||||
(fn [acc route]
|
|
||||||
(into acc (walk [path meta] route)))
|
|
||||||
[]
|
|
||||||
routes))]
|
|
||||||
(if (vector? (first routes))
|
(if (vector? (first routes))
|
||||||
(subwalk pacc macc routes)
|
(subwalk pacc macc routes)
|
||||||
(let [[path & [maybe-meta :as args]] routes]
|
(let [[path & [maybe-meta :as args]] routes]
|
||||||
(let [[meta childs] (if-not (vector? maybe-meta)
|
(let [[meta childs] (if (vector? maybe-meta)
|
||||||
[maybe-meta (rest args)]
|
[{} args]
|
||||||
[{} args])
|
[maybe-meta (rest args)])
|
||||||
macc (into macc (expand meta))]
|
macc (into macc (expand meta))]
|
||||||
(if (seq childs)
|
(if (seq childs)
|
||||||
(subwalk (str pacc path) macc childs)
|
(subwalk (str pacc path) macc childs)
|
||||||
|
|
@ -58,16 +54,13 @@
|
||||||
(defn map-meta [f routes]
|
(defn map-meta [f routes]
|
||||||
(mapv #(update % 1 f) routes))
|
(mapv #(update % 1 f) routes))
|
||||||
|
|
||||||
(defn merge-meta
|
(defn merge-meta [key-strategy x]
|
||||||
([x]
|
(reduce
|
||||||
(merge-meta (constantly :into) x))
|
(fn [acc [k v]]
|
||||||
([key-strategy x]
|
(let [strategy (or (key-strategy k) :replace)]
|
||||||
(reduce
|
(deep-merge strategy acc {k v})))
|
||||||
(fn [acc [k v]]
|
{}
|
||||||
(let [strategy (or (key-strategy k) :replace)]
|
x))
|
||||||
(deep-merge strategy acc {k v})))
|
|
||||||
{}
|
|
||||||
x)))
|
|
||||||
|
|
||||||
(defn resolve-routes
|
(defn resolve-routes
|
||||||
([x]
|
([x]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue