Merge pull request #69 from erubi/master
Update reagent6/events.cljs to use interceptors
This commit is contained in:
commit
a693c8f1e3
|
@ -4,9 +4,9 @@
|
|||
[clojure.spec :as s]
|
||||
[$PROJECT_NAME_HYPHENATED$.db :as db :refer [app-db]]))
|
||||
|
||||
;; -- Middleware ------------------------------------------------------------
|
||||
;; -- Interceptors ------------------------------------------------------------
|
||||
;;
|
||||
;; See https://github.com/Day8/re-frame/wiki/Using-Handler-Middleware
|
||||
;; See https://github.com/Day8/re-frame/blob/master/docs/Interceptors.md
|
||||
;;
|
||||
(defn check-and-throw
|
||||
"Throw an exception if db doesn't have a valid spec."
|
||||
|
@ -15,7 +15,7 @@
|
|||
(let [explain-data (s/explain-data spec db)]
|
||||
(throw (ex-info (str "Spec check failed: " explain-data) explain-data)))))
|
||||
|
||||
(def validate-spec-mw
|
||||
(def validate-spec
|
||||
(if goog.DEBUG
|
||||
(after (partial check-and-throw ::db/app-db))
|
||||
[]))
|
||||
|
@ -24,12 +24,12 @@
|
|||
|
||||
(reg-event-db
|
||||
:initialize-db
|
||||
validate-spec-mw
|
||||
validate-spec
|
||||
(fn [_ _]
|
||||
app-db))
|
||||
|
||||
(reg-event-db
|
||||
:set-greeting
|
||||
validate-spec-mw
|
||||
validate-spec
|
||||
(fn [db [_ value]]
|
||||
(assoc db :greeting value)))
|
||||
|
|
Loading…
Reference in New Issue