dynamic navs automatically compile sequence returns if completely static
This commit is contained in:
parent
e2ec017c6b
commit
72e004df23
1 changed files with 16 additions and 8 deletions
|
|
@ -114,8 +114,22 @@
|
||||||
attr)]
|
attr)]
|
||||||
[(with-meta name attr) macro-args]))
|
[(with-meta name attr) macro-args]))
|
||||||
|
|
||||||
|
(defn- static-path? [path]
|
||||||
|
(if (sequential? path)
|
||||||
|
(every? static-path? path)
|
||||||
|
(-> path i/dynamic-param? not)
|
||||||
|
))
|
||||||
|
|
||||||
|
(defn- wrap-dynamic-nav [f]
|
||||||
|
(fn [& args]
|
||||||
|
(let [ret (apply f args)]
|
||||||
|
(if (and (sequential? ret) (static-path? ret))
|
||||||
|
(i/comp-paths* ret)
|
||||||
|
ret
|
||||||
|
))))
|
||||||
|
|
||||||
(defmacro dynamicnav [& args]
|
(defmacro dynamicnav [& args]
|
||||||
`(vary-meta (fn ~@args) assoc :dynamicnav true))
|
`(vary-meta (wrap-dynamic-nav (fn ~@args)) assoc :dynamicnav true))
|
||||||
|
|
||||||
(defmacro defdynamicnav
|
(defmacro defdynamicnav
|
||||||
"Defines a function that can choose what navigator to use at runtime based on
|
"Defines a function that can choose what navigator to use at runtime based on
|
||||||
|
|
@ -558,13 +572,7 @@
|
||||||
[navfn]
|
[navfn]
|
||||||
(let [latenavfn (late-resolved-fn navfn)]
|
(let [latenavfn (late-resolved-fn navfn)]
|
||||||
(dynamicnav [& args]
|
(dynamicnav [& args]
|
||||||
(if (= 1 (count args))
|
(map latenavfn args))))
|
||||||
;; optimization if dynamicnav is used in a runtime situation (like
|
|
||||||
;; via a dynamic var)
|
|
||||||
;; also makes the resulting nav function semantically identical to original
|
|
||||||
;; nav by returning a RichNavigator instead of a sequence
|
|
||||||
(latenavfn (first args))
|
|
||||||
(map latenavfn args)))))
|
|
||||||
|
|
||||||
|
|
||||||
;; Helpers for making recursive or mutually recursive navs
|
;; Helpers for making recursive or mutually recursive navs
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue