Skip to content

Instantly share code, notes, and snippets.

@olivergeorge
Created July 8, 2016 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olivergeorge/c4a26886b7bbd05f2e9018614a2213ff to your computer and use it in GitHub Desktop.
Save olivergeorge/c4a26886b7bbd05f2e9018614a2213ff to your computer and use it in GitHub Desktop.
(defn spec-checking-fn
"Patch for spec-checking-fn which doesn't serialize full data structure to string"
[v f]
(let [conform! (fn [v role spec data args]
(let [conformed (s/conform spec data)]
(if (= ::s/invalid conformed)
(let [ed (assoc (s/explain-data* spec [role] [] [] data)
::s/args args)]
(js/console.debug (str "Call to " (pr-str v) " did not conform to spec"))
(doseq [problem (::s/problems ed)]
(js/console.debug problem))
(throw (ex-info (str "Call to " (pr-str v) " did not conform to spec") ed)))
conformed)))]
(cond->
(fn
[& args]
(if cljs.spec/*instrument-enabled*
(s/with-instrument-disabled
(let [specs (s/get-spec v)]
(when (:args specs) (conform! v :args (:args specs) args args))
(binding [cljs.spec/*instrument-enabled* true]
(apply f args))))
(apply f args)))
(not (instance? MultiFn f)) (doto (gobj/extend f)))))
(set! cljs.spec/spec-checking-fn spec-checking-fn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment