I'm using re-frame with spec to validate app-db
, much like in the todomvc example.
When a user makes an invalid entry, I'm using s/explain-data
(in a re-frame interceptor) to return a problems
map naming the :pred
icate which caused validation failure. This predicate is a symbol like project.db/validation-function
.
My validation function has metadata which is accessible from the repl using:
(meta #'project.db/validation-function)
The function definition (in the project.db
namespace) looks like this:
(defn validation-function
"docstring..."
{:error-message "error message"}
[param]
(function-body...)
The problem is I can't work out how to retrieve the metadata dynamically (working in project.events
namespace), for example:
(let [explain-data (s/explain-data spec db)
pred (->> (:cljs.spec.alpha/problems explain-data) first :pred)
msg (what-goes-here? pred)]
msg)
I've tried the following things in place of what-goes-here?
:
symbol?
givestrue
str
gives"project.db/validation-function"
meta
givesnil
var
gives a compile-time error "Unable to resolve var: p1__46744# in this context"
I think the problem is that I'm getting a symbol, but I need the var it refers to, which is where the metadata lives.
I've tried using a macro, but don't really know what I'm doing. This is the closest discussion I could find, but I couldn't work it out.
Help!