From 06d8fccf89df689782aeb3edb32ce35d8a6676ef Mon Sep 17 00:00:00 2001 From: Mike Thompson Date: Wed, 17 Aug 2016 23:18:16 +1000 Subject: [PATCH] Interceptors now have an `id` and not a `name`. Code now matches the docs. --- src/re_frame/interceptor.cljc | 12 +++++++----- src/re_frame/std_interceptors.cljc | 23 ++++++++++++----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/re_frame/interceptor.cljc b/src/re_frame/interceptor.cljc index 244b045..7033041 100644 --- a/src/re_frame/interceptor.cljc +++ b/src/re_frame/interceptor.cljc @@ -7,7 +7,7 @@ ;; XXX use defrecord ?? -(def mandatory-interceptor-keys #{:name :after :before}) +(def mandatory-interceptor-keys #{:id :after :before}) (defn interceptor? @@ -18,13 +18,15 @@ (defn ->interceptor "Create an interceptor from named arguements" - [& {:as m :keys [name before after]}] + [& {:as m :keys [name id before after]}] ;; remove `name` in due course - only in there as a backwards compat thing (when debug-enabled? + (if name + (console :warn "re-frame.core/->interceptor no longer takes `:name` - has been renamed to `:id`. Please change for " name)) (if-let [unknown-keys (seq (clojure.set/difference - (-> m keys set) + (-> (dissoc m :name) keys set) ;; XXX temporarily take out name mandatory-interceptor-keys))] - (console :error "re-frame: interceptor " name " has unknown keys: " unknown-keys))) - {:name (or name :unnamed) + (console :error "re-frame: ->interceptor " m " has unknown keys: " unknown-keys))) + {:id (or id name :unnamed) ;; XXX remove `name` in due course :before before :after after }) diff --git a/src/re_frame/std_interceptors.cljc b/src/re_frame/std_interceptors.cljc index e0cbf49..9951e25 100644 --- a/src/re_frame/std_interceptors.cljc +++ b/src/re_frame/std_interceptors.cljc @@ -26,7 +26,7 @@ code. See the todomvc example to see how to exclude interceptors from production code." (->interceptor - :name :debug + :id :debug :before (fn debug-before [context] (console :log "Handling re-frame event: " (-> context :coeffects :event)) @@ -50,15 +50,16 @@ (def trim-v - "An interceptor which removes the first element of the event vector, allowing you to write - more aesthetically pleasing db handlers. No leading underscore on the event-v! + "An interceptor which removes the first element of the event vector, + allowing you to write more aesthetically pleasing db handlers. No + leading underscore on the event-v! Your event handlers will look like this: (defn my-handler [db [x y z]] ;; <-- instead of [_ x y z] ....)" (->interceptor - :name :trim-v + :id :trim-v :before (fn trimv-before [context] (->> (get-coeffect context :event) @@ -86,7 +87,7 @@ 3. stores the db result back into context's `:effects`" [handler-fn] (->interceptor - :name :db-handler + :id :db-handler :before (fn db-handler-before [context] (let [{:keys [db event]} (:coeffects context)] @@ -109,7 +110,7 @@ 3. stores the result back into the `:effects`" [handler-fn] (->interceptor - :name :fx-handler + :id :fx-handler :before (fn fx-handler-before [context] (let [{:keys [event] :as coeffects} (:coeffects context)] @@ -125,7 +126,7 @@ (enqueue context [more interceptors]))" [handler-fn] (->interceptor - :name :ctx-handler + :id :ctx-handler :before handler-fn)) @@ -154,7 +155,7 @@ (when (empty? path) (console :error "re-frame: \"path\" interceptor given no params" )) (->interceptor - :name :path + :id :path :before (fn [context] (let [original-db (get-coeffect context :db)] @@ -205,7 +206,7 @@ ensure this important step is not missed." [f] (->interceptor - :name :enrich + :id :enrich :after (fn enrich-after [context] (let [event (get-coeffect context :event) @@ -227,7 +228,7 @@ - `f` writes some aspect of db to localstorage." [f] (->interceptor - :name :after + :id :after :after (fn after-after [context] (let [db (get-effect context :db) @@ -258,7 +259,7 @@ " [f out-path & in-paths] (->interceptor - :name :enrich + :id :enrich :after (fn on-change-after [context] (let [new-db (get-effect context :db)