Often we make an API ns that serves to alias various functions from other namespaces so that another namespace (e.g. routes) can stay clean of the abundance of :require s. Is there a way to do this while keeping the docstring from the original fn, for tooling purposes?
Example:
;; in "sources"
(defn sources-summary
"Get all sources with their info.
[{:source-name \"wsj\"
:id xyz
:material-quantity 42
:complete-percent 80
}] "
[]
;; implementation
)
;; in the API NS. How should I keep the docstring?
(def get-sources sources/sources-summary)
(defalias plus +)
(doc plus)
-------------------------
clojure.core/+
([] [x] [x y] [x y & more])
Alias for +.
Returns the sum of nums. (+) returns 0. Does not auto-promote
longs, will throw on overflow. See also: +'
I don’t recommend abusing these. I find it very useful to be able to just look at a namespace form or a function and know what it depends on, and aliases make that more difficult.
I don’t think I’m actually using these in any of my code. I originally wrote them when I was using CouchDB and was making a library to provide more functionality than clutch, but I didn’t want to have to require both my library and clutch in every namespace (and remember which function belongs to which). Other than that, I have never found the loss of clarity to be worth saving a few lines of typing.
Has anyone used import-vars in the context of clojurescript?
I’m trying to get some vars (macros and functions) in one namespace to be exposed in another where the consuming namespace is in clojurescript.
Or any strategy for creating aliases in clojurescript, with the docstring of the target var copied over also.
You’d think there’s no reason it shouldn’t be compatible with cljs since it’s all pure-clojure functionality, but I see that Potemkin is all written in clj and not cljc, so looks like it might not work for you