Skip to content

Commit 8399062

Browse files
author
dnolen
committed
CLJS-1787: Make cljs.spec explain pluggable
same as Clojure commit 99ab306
1 parent 30ab498 commit 8399062

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/cljs/cljs/spec.cljs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@
177177
[spec x]
178178
(explain-data* spec [] (if-let [name (spec-name spec)] [name] []) [] x))
179179

180-
(defn explain-out
181-
"prints an explanation to *out*."
180+
(defn explain-printer
181+
"Default printer for explain-data. nil indicates a successful validation."
182182
[ed]
183183
(if ed
184184
(print
@@ -209,6 +209,14 @@
209209
(newline)))))
210210
(println "Success!")))
211211

212+
(def ^:dynamic *explain-out* explain-printer)
213+
214+
(defn explain-out
215+
"Prints explanation data (per 'explain-data') to *out* using the printer in *explain-out*,
216+
by default explain-printer."
217+
[ed]
218+
(*explain-out* ed))
219+
212220
(defn explain
213221
"Given a spec and a value that fails to conform, prints an explanation to *out*."
214222
[spec x]

0 commit comments

Comments
 (0)