Interceptors now have an `id` and not a `name`. Code now matches the docs.
This commit is contained in:
parent
ff2b712379
commit
06d8fccf89
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
;; XXX use defrecord ??
|
;; XXX use defrecord ??
|
||||||
|
|
||||||
(def mandatory-interceptor-keys #{:name :after :before})
|
(def mandatory-interceptor-keys #{:id :after :before})
|
||||||
|
|
||||||
|
|
||||||
(defn interceptor?
|
(defn interceptor?
|
||||||
|
@ -18,13 +18,15 @@
|
||||||
|
|
||||||
(defn ->interceptor
|
(defn ->interceptor
|
||||||
"Create an interceptor from named arguements"
|
"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?
|
(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
|
(if-let [unknown-keys (seq (clojure.set/difference
|
||||||
(-> m keys set)
|
(-> (dissoc m :name) keys set) ;; XXX temporarily take out name
|
||||||
mandatory-interceptor-keys))]
|
mandatory-interceptor-keys))]
|
||||||
(console :error "re-frame: interceptor " name " has unknown keys: " unknown-keys)))
|
(console :error "re-frame: ->interceptor " m " has unknown keys: " unknown-keys)))
|
||||||
{:name (or name :unnamed)
|
{:id (or id name :unnamed) ;; XXX remove `name` in due course
|
||||||
:before before
|
:before before
|
||||||
:after after })
|
:after after })
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
code. See the todomvc example to see how to exclude interceptors from
|
code. See the todomvc example to see how to exclude interceptors from
|
||||||
production code."
|
production code."
|
||||||
(->interceptor
|
(->interceptor
|
||||||
:name :debug
|
:id :debug
|
||||||
:before (fn debug-before
|
:before (fn debug-before
|
||||||
[context]
|
[context]
|
||||||
(console :log "Handling re-frame event: " (-> context :coeffects :event))
|
(console :log "Handling re-frame event: " (-> context :coeffects :event))
|
||||||
|
@ -50,15 +50,16 @@
|
||||||
|
|
||||||
|
|
||||||
(def trim-v
|
(def trim-v
|
||||||
"An interceptor which removes the first element of the event vector, allowing you to write
|
"An interceptor which removes the first element of the event vector,
|
||||||
more aesthetically pleasing db handlers. No leading underscore on the event-v!
|
allowing you to write more aesthetically pleasing db handlers. No
|
||||||
|
leading underscore on the event-v!
|
||||||
Your event handlers will look like this:
|
Your event handlers will look like this:
|
||||||
|
|
||||||
(defn my-handler
|
(defn my-handler
|
||||||
[db [x y z]] ;; <-- instead of [_ x y z]
|
[db [x y z]] ;; <-- instead of [_ x y z]
|
||||||
....)"
|
....)"
|
||||||
(->interceptor
|
(->interceptor
|
||||||
:name :trim-v
|
:id :trim-v
|
||||||
:before (fn trimv-before
|
:before (fn trimv-before
|
||||||
[context]
|
[context]
|
||||||
(->> (get-coeffect context :event)
|
(->> (get-coeffect context :event)
|
||||||
|
@ -86,7 +87,7 @@
|
||||||
3. stores the db result back into context's `:effects`"
|
3. stores the db result back into context's `:effects`"
|
||||||
[handler-fn]
|
[handler-fn]
|
||||||
(->interceptor
|
(->interceptor
|
||||||
:name :db-handler
|
:id :db-handler
|
||||||
:before (fn db-handler-before
|
:before (fn db-handler-before
|
||||||
[context]
|
[context]
|
||||||
(let [{:keys [db event]} (:coeffects context)]
|
(let [{:keys [db event]} (:coeffects context)]
|
||||||
|
@ -109,7 +110,7 @@
|
||||||
3. stores the result back into the `:effects`"
|
3. stores the result back into the `:effects`"
|
||||||
[handler-fn]
|
[handler-fn]
|
||||||
(->interceptor
|
(->interceptor
|
||||||
:name :fx-handler
|
:id :fx-handler
|
||||||
:before (fn fx-handler-before
|
:before (fn fx-handler-before
|
||||||
[context]
|
[context]
|
||||||
(let [{:keys [event] :as coeffects} (:coeffects context)]
|
(let [{:keys [event] :as coeffects} (:coeffects context)]
|
||||||
|
@ -125,7 +126,7 @@
|
||||||
(enqueue context [more interceptors]))"
|
(enqueue context [more interceptors]))"
|
||||||
[handler-fn]
|
[handler-fn]
|
||||||
(->interceptor
|
(->interceptor
|
||||||
:name :ctx-handler
|
:id :ctx-handler
|
||||||
:before handler-fn))
|
:before handler-fn))
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,7 +155,7 @@
|
||||||
(when (empty? path)
|
(when (empty? path)
|
||||||
(console :error "re-frame: \"path\" interceptor given no params" ))
|
(console :error "re-frame: \"path\" interceptor given no params" ))
|
||||||
(->interceptor
|
(->interceptor
|
||||||
:name :path
|
:id :path
|
||||||
:before (fn
|
:before (fn
|
||||||
[context]
|
[context]
|
||||||
(let [original-db (get-coeffect context :db)]
|
(let [original-db (get-coeffect context :db)]
|
||||||
|
@ -205,7 +206,7 @@
|
||||||
ensure this important step is not missed."
|
ensure this important step is not missed."
|
||||||
[f]
|
[f]
|
||||||
(->interceptor
|
(->interceptor
|
||||||
:name :enrich
|
:id :enrich
|
||||||
:after (fn enrich-after
|
:after (fn enrich-after
|
||||||
[context]
|
[context]
|
||||||
(let [event (get-coeffect context :event)
|
(let [event (get-coeffect context :event)
|
||||||
|
@ -227,7 +228,7 @@
|
||||||
- `f` writes some aspect of db to localstorage."
|
- `f` writes some aspect of db to localstorage."
|
||||||
[f]
|
[f]
|
||||||
(->interceptor
|
(->interceptor
|
||||||
:name :after
|
:id :after
|
||||||
:after (fn after-after
|
:after (fn after-after
|
||||||
[context]
|
[context]
|
||||||
(let [db (get-effect context :db)
|
(let [db (get-effect context :db)
|
||||||
|
@ -258,7 +259,7 @@
|
||||||
"
|
"
|
||||||
[f out-path & in-paths]
|
[f out-path & in-paths]
|
||||||
(->interceptor
|
(->interceptor
|
||||||
:name :enrich
|
:id :enrich
|
||||||
:after (fn on-change-after
|
:after (fn on-change-after
|
||||||
[context]
|
[context]
|
||||||
(let [new-db (get-effect context :db)
|
(let [new-db (get-effect context :db)
|
||||||
|
|
Loading…
Reference in New Issue