Skip to content

Commit

Permalink
feat: add cljs.spec.alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
defclass committed Nov 9, 2020
1 parent 3ea34de commit 9fda0a4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
hickory {:mvn/version "0.7.1"}
hiccups {:mvn/version "0.3.0"}
tongue {:mvn/version "0.2.9"}
org.clojure/core.async {:mvn/version "1.3.610"}}
org.clojure/core.async {:mvn/version "1.3.610"}
expound {:mvn/version "0.8.6"}}

:aliases {:cljs {:extra-paths ["src/dev-cljs/"]
:extra-deps {org.clojure/clojurescript {:mvn/version "1.10.520"}
Expand Down
20 changes: 20 additions & 0 deletions src/main/frontend/spec.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(ns frontend.spec
(:require [cljs.spec.alpha :as s]
[frontend.config :as config]
[expound.alpha :as expound]))

;; disable in production
(when config/dev? (s/check-asserts true))

(set! s/*explain-out* expound/printer)

(defn validate [spec value]
(when-let [error (s/explain-data spec value)]
(if config/dev?
(throw (ex-info (expound/expound-str spec value) error))
(js/console.log (expound/expound-str spec value)))))

(s/def :user/repo string?)

(comment
(validate :user/repo 1))

0 comments on commit 9fda0a4

Please sign in to comment.