Skip to content

Commit 7084cfc

Browse files
author
dnolen
committed
maintain compile time registry in addition to runtime registry
1 parent 5a78c9f commit 7084cfc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/cljs/cljs/spec.cljc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
[cljs.spec.impl.gen :as gen]
1616
[clojure.string :as str]))
1717

18+
(defonce registry-ref (atom {}))
19+
1820
(defn- ->sym
1921
"Returns a symbol from a symbol or var"
2022
[x]
@@ -51,8 +53,10 @@
5153
spec-name, predicate or regex-op makes an entry in the registry mapping k to
5254
the spec"
5355
[k spec-form]
54-
(let [k (if (symbol? k) (ns-qualify &env k) k)]
55-
`(cljs.spec/def-impl '~k '~(res &env spec-form) ~spec-form)))
56+
(let [k (if (symbol? k) (ns-qualify &env k) k)
57+
form (res &env spec-form)]
58+
(swap! registry-ref assoc k form)
59+
`(cljs.spec/def-impl '~k '~form ~spec-form)))
5660

5761
(defmacro spec
5862
"Takes a single predicate form, e.g. can be the name of a predicate,

0 commit comments

Comments
 (0)