Fork me on GitHub
#clojure-spec
<
2020-06-27
>
jaide08:06:30

Does anyone have or know of any examples of using spec with reagent views?

Joe Lane15:07:28

Hey @jayzawrotny, I'm a little late to the party, but I found this blog post to be very apropos https://juxt.pro/blog/cljs-apps

borkdude09:06:42

@jayzawrotny I do have one example from a commercial app I've worked on for the last few years:

(s/fdef dre.components.widget/widget
  :args
  (s/and
   (s/cat
    :opts
    (s/keys
     :req-un [::title ;; title in header
              ::content ;; Contents to show in widget. It must be a Hiccup
              ;; vector. Widget does not support varying arguments in
              ;; content, they are for initialization only.
              ]
     :opt-un [::id ;; unique identifier for widget (page wide, not app
              ;; wide)
              ::icon ;; icon to show in header
              ::widget-class ;; CSS class
              ::collapsable? ;; If it can be collapsed
              ::init-collapsed? ;; initialize the widget in a collapsed
              ;; state?
              ::help ;; help contents which are shown in modal
              ::controls ;; Arbitrary component rendered in the
              ;; header. What it does is up to you.
              ::selections ;; coll of dropdown/tabs
              ::dropdown ;; convenience option, singular version of
              ;; selections with
              ;; {:type :dropdown, :id :dropdown} by default
              ::tabs ;; convenience option, singular version of selections
              ;; with {:type :tabs, :id :tabs}
              ::loading? ;; Whether or not to display a loading indicator
              ::locked? ;; Whether or not content modifications are possible
              ::menu ;; menu
              ::on-will-unmount]))
   (fn [{:keys [opts]}]
     (if-let [unexpected
              (seq (apply dissoc opts expected-keys))]
       (do
         (warn "Unexpected options" unexpected)
         false)
       true))))

borkdude09:06:49

@jayzawrotny This is about the only Reagent component I've spec-ed because it has so many options

borkdude09:06:39

Not sure if it's useful, but this is the app: http://covid19.doctorevidence.com/ (this is a free preview of it)

jaide18:06:03

Thanks @borkdude this really helps!