mirror of
https://github.com/metosin/reitit.git
synced 2025-12-23 02:41:10 +00:00
Flatten nested lets
This commit is contained in:
parent
32598f0e56
commit
33e3658a79
1 changed files with 16 additions and 16 deletions
|
|
@ -19,7 +19,7 @@
|
||||||
:cljs cljs.core.PersistentHashMap)
|
:cljs cljs.core.PersistentHashMap)
|
||||||
(expand [this] this)
|
(expand [this] this)
|
||||||
|
|
||||||
#?(:clj clojure.lang.Fn
|
#?(:clj clojure.lang.Fn
|
||||||
:cljs function)
|
:cljs function)
|
||||||
(expand [this] {:handler this})
|
(expand [this] {:handler this})
|
||||||
|
|
||||||
|
|
@ -28,21 +28,21 @@
|
||||||
|
|
||||||
(defn walk [data {:keys [path meta routes expand]
|
(defn walk [data {:keys [path meta routes expand]
|
||||||
:or {path "", meta [], routes [], expand expand}}]
|
:or {path "", meta [], routes [], expand expand}}]
|
||||||
(letfn
|
(letfn
|
||||||
[(walk-many [p m r]
|
[(walk-many [p m r]
|
||||||
(reduce #(into %1 (walk-one p m %2)) [] r))
|
(reduce #(into %1 (walk-one p m %2)) [] r))
|
||||||
(walk-one [pacc macc routes]
|
(walk-one [pacc macc routes]
|
||||||
(if (vector? (first routes))
|
(if (vector? (first routes))
|
||||||
(walk-many pacc macc routes)
|
(walk-many pacc macc routes)
|
||||||
(let [[path & [maybe-meta :as args]] routes]
|
(let [[path & [maybe-meta :as args]] routes
|
||||||
(let [[meta childs] (if (vector? maybe-meta)
|
[meta childs] (if (vector? maybe-meta)
|
||||||
[{} args]
|
[{} args]
|
||||||
[maybe-meta (rest args)])
|
[maybe-meta (rest args)])
|
||||||
macc (into macc (expand meta))]
|
macc (into macc (expand meta))]
|
||||||
(if (seq childs)
|
(if (seq childs)
|
||||||
(walk-many (str pacc path) macc childs)
|
(walk-many (str pacc path) macc childs)
|
||||||
[[(str pacc path) macc]])))))]
|
[[(str pacc path) macc]]))))]
|
||||||
(walk-one path meta data)))
|
(walk-one path meta data)))
|
||||||
|
|
||||||
(defn map-meta [f routes]
|
(defn map-meta [f routes]
|
||||||
(mapv #(update % 1 f) routes))
|
(mapv #(update % 1 f) routes))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue