Fork me on GitHub
#re-frame
<
2017-12-06
>
oliy18:12:01

I've got re-graph to its first release: https://github.com/oliyh/re-graph

jonr19:12:42

anyone have any tips on tracking down which event is causing a spec validation to fail? I have a similar setup to the re-frame todomvc which is working well but when something fails it would be extremely helpful to know which reg-event-db or reg-event-fx caused the failure

p-himik19:12:50

@jonr If you check the spec in an interceptor, you have full access to the context that contain the event vector.

jonr19:12:55

ahh, duh. Didn't think about it like that. Makes good sense

jonr20:12:08

gonna try that out now. Thanks @p-himik

jonr20:12:03

I was just using after (again taken form the TODOMVC) but will I need to make my own interceptor which does something like pass on the context to the spec validation so it can log/print it?

p-himik20:12:19

@jonr Here's how I do it:

(defn check-and-throw
  "throw an exception if db doesn't match the spec."
  [a-spec db event]
  (when-not (sp/valid? a-spec db)
    (let [data (sp/explain-data a-spec db)]
      (throw (ex-info "DB spec check failed" (assoc data :db db :event event))))))

(def check-spec-i (after (fn [db event]
                           (when db
                             (check-and-throw :some.ns/db-spec db event)))))

jonr20:12:14

awesome 💥 that's just about what I was thinking. Thanks!

jonr20:12:10

I'm still pretty new to re-frame, is it common/idiomatic to spec validate the entire db?

p-himik20:12:02

I obviously cannot say for others, but I validate the entire db on each event. It doesn't have any significant performance impact in my case.

jonr20:12:36

that's what I was wondering.

jonr20:12:43

big thanks again @p-himik that did just what I wanted!

p-himik20:12:58

No problem. 🙂

jeaye20:12:20

We validate all events as well, using orchestra.