Merge pull request #69 from erubi/master
Update reagent6/events.cljs to use interceptors
This commit is contained in:
commit
a693c8f1e3
|
@ -1,12 +1,12 @@
|
|||
(ns $PROJECT_NAME_HYPHENATED$.events
|
||||
(:require
|
||||
[re-frame.core :refer [reg-event-db after]]
|
||||
[clojure.spec :as s]
|
||||
[$PROJECT_NAME_HYPHENATED$.db :as db :refer [app-db]]))
|
||||
[re-frame.core :refer [reg-event-db after]]
|
||||
[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))
|
||||
[]))
|
||||
|
@ -23,13 +23,13 @@
|
|||
;; -- Handlers --------------------------------------------------------------
|
||||
|
||||
(reg-event-db
|
||||
:initialize-db
|
||||
validate-spec-mw
|
||||
(fn [_ _]
|
||||
app-db))
|
||||
:initialize-db
|
||||
validate-spec
|
||||
(fn [_ _]
|
||||
app-db))
|
||||
|
||||
(reg-event-db
|
||||
:set-greeting
|
||||
validate-spec-mw
|
||||
(fn [db [_ value]]
|
||||
(assoc db :greeting value)))
|
||||
:set-greeting
|
||||
validate-spec
|
||||
(fn [db [_ value]]
|
||||
(assoc db :greeting value)))
|
||||
|
|
Loading…
Reference in New Issue