Merge pull request #69 from erubi/master

Update reagent6/events.cljs to use interceptors
This commit is contained in:
Artūr Girenko 2016-10-03 18:48:40 +02:00 committed by GitHub
commit a693c8f1e3
1 changed files with 14 additions and 14 deletions

View File

@ -4,9 +4,9 @@
[clojure.spec :as s] [clojure.spec :as s]
[$PROJECT_NAME_HYPHENATED$.db :as db :refer [app-db]])) [$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 (defn check-and-throw
"Throw an exception if db doesn't have a valid spec." "Throw an exception if db doesn't have a valid spec."
@ -15,7 +15,7 @@
(let [explain-data (s/explain-data spec db)] (let [explain-data (s/explain-data spec db)]
(throw (ex-info (str "Spec check failed: " explain-data) explain-data))))) (throw (ex-info (str "Spec check failed: " explain-data) explain-data)))))
(def validate-spec-mw (def validate-spec
(if goog.DEBUG (if goog.DEBUG
(after (partial check-and-throw ::db/app-db)) (after (partial check-and-throw ::db/app-db))
[])) []))
@ -24,12 +24,12 @@
(reg-event-db (reg-event-db
:initialize-db :initialize-db
validate-spec-mw validate-spec
(fn [_ _] (fn [_ _]
app-db)) app-db))
(reg-event-db (reg-event-db
:set-greeting :set-greeting
validate-spec-mw validate-spec
(fn [db [_ value]] (fn [db [_ value]]
(assoc db :greeting value))) (assoc db :greeting value)))