Add :gen/resolve property#1043
Conversation
This works much like `:gen/gen`, but will first attempt to resolve the fully-qualified symbol. This separation means that malli schemas are free to carry around this extra data about where generators live, without having to have them loaded at runtime. Instead, generators declared in this way are dynamically loaded when used.
|
Thanks for the PR. Quick comments:
[:int {:gen/resolve 'mount.core/stop}] |
|
Thanks for the feedback!
I'm curious if there's a pattern that makes more sense for lazy-loading that would be regardless of platform.
That's a good idea. I might look into sci or dynaload or somesuch for this kind of dynamic loading. Taking a step back, is this idea useful? And if so, is this the way that it ought to be implemented? My desire is for a serializable schema (dependency-free) that can still point at more sophisticated generators that may or may not be available at runtime. My use-case is generators that do exist on the classpath in production, but are available to tests. |
|
IMO this is useful. Perhaps a simpler cross-platform implementation would be (ns spec-ns
(def schema [:map {:gen/gen `(gen-ns/my-generator)} ...])
(ns gen-ns)
(defn my-generator [] ...)
(ns test-ns
(:require spec-ns gen-ns))
(m/generate spec-ns/schema)It would also be nice if |
|
I agree using |
This works much like
:gen/gen, but will first attempt to resolve the fully-qualified symbol.This separation means that malli schemas are free to carry around this extra data about where generators live, without having to have them loaded at runtime. Instead, generators declared in this way are dynamically loaded when used.