feat: add cljs.spec.alpha

This commit is contained in:
defclass
2020-10-30 18:14:16 +08:00
parent 3ea34ded54
commit 9fda0a4c03
2 changed files with 22 additions and 1 deletions

View File

@@ -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))