mirror of
https://github.com/logseq/logseq.git
synced 2026-05-05 03:16:37 +00:00
feat: add cljs.spec.alpha
This commit is contained in:
20
src/main/frontend/spec.cljs
Normal file
20
src/main/frontend/spec.cljs
Normal 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))
|
||||
Reference in New Issue
Block a user