diff --git a/.editorconfig b/.editorconfig
index 86c8f59..13ef57c 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,7 +1,7 @@
root = true
[*]
-indent_style = tab
+indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml
index adb5ab9..c374ce3 100644
--- a/.idea/codeStyleSettings.xml
+++ b/.idea/codeStyleSettings.xml
@@ -12,6 +12,5 @@
-
\ No newline at end of file
diff --git a/src/re_frame/fx.cljc b/src/re_frame/fx.cljc
index 99879e4..0cb84d6 100644
--- a/src/re_frame/fx.cljc
+++ b/src/re_frame/fx.cljc
@@ -30,14 +30,12 @@
call the registered effects handlers for each of the map's keys:
`:dispatch`, `:undo` and `:db`."
(->interceptor
- :id :do-fx
- :after (fn do-fx-after
- [context]
- (->> (:effects context)
- (map (fn [[k value]]
- (if-let [effect-fn (get-handler kind k true)]
- (effect-fn value))))
- doall))))
+ :id :do-fx
+ :after (fn do-fx-after
+ [context]
+ (doseq [[effect-k value] (:effects context)]
+ (if-let [effect-fn (get-handler kind effect-k true)]
+ (effect-fn value))))))
;; -- Builtin Effect Handlers ------------------------------------------------
@@ -54,8 +52,8 @@
(register
:dispatch-later
(fn [value]
- (doseq [{:keys [ms dispatch] :as effect} value]
- (if (or (empty? dispatch) (-> ms number? not))
+ (doseq [{:keys [ms dispatch] :as effect} value]
+ (if (or (empty? dispatch) (not (number? ms)))
(console :error "re-frame: ignoring bad :dispatch-later value:" effect)
(set-timeout! #(router/dispatch dispatch) ms)))))
@@ -106,8 +104,8 @@
(fn [value]
(let [clear-event (partial clear-handlers events/kind)]
(if (sequential? value)
- (doall (map clear-event value))
- (clear-event value)))))
+ (doseq [event (if (sequential? value) value [value])]
+ (clear-event event))))))
;; :db
diff --git a/src/re_frame/interceptor.cljc b/src/re_frame/interceptor.cljc
index e6cb91b..cea7224 100644
--- a/src/re_frame/interceptor.cljc
+++ b/src/re_frame/interceptor.cljc
@@ -52,13 +52,17 @@
(:coeffects context))
([context key]
(get-in context [:coeffects key]))
- ([context key not-fount]
- (get-in context [:coeffects key] not-fount)))
+ ([context key not-found]
+ (get-in context [:coeffects key] not-found)))
(defn assoc-coeffect
[context key value]
(assoc-in context [:coeffects key] value))
+(defn update-coeffect
+ [context key f & args]
+ (apply update context key f args))
+
;; -- Execute Interceptor Chain ------------------------------------------------------------------
@@ -101,8 +105,8 @@
(let [interceptor (peek queue) ;; next interceptor to call
stack (:stack context)] ;; already completed interceptors
(recur (-> context
- (assoc :queue (pop queue))
- (assoc :stack (conj stack interceptor))
+ (assoc :queue (pop queue)
+ :stack (conj stack interceptor))
(invoke-interceptor-fn interceptor direction)))))))))
diff --git a/src/re_frame/registrar.cljc b/src/re_frame/registrar.cljc
index 3f033a3..aceecb8 100644
--- a/src/re_frame/registrar.cljc
+++ b/src/re_frame/registrar.cljc
@@ -26,15 +26,15 @@
([kind id required?]
(let [handler (get-handler kind id)]
- (when debug-enabled?
- (when (and required? (nil? handler))
+ (when debug-enabled? ;; This is in a separate when so Closure DCE can run
+ (when (and required? (nil? handler)) ;; Otherwise you'd need to type hint the and with a ^boolean for DCE.
(console :error "re-frame: no " (str kind) " handler registered for:" id)))
handler)))
(defn register-handler
[kind id handler-fn]
- (when debug-enabled?
+ (when debug-enabled? ;; This is in a separate when so Closure DCE can run
(when (get-handler kind id false)
(console :warn "re-frame: overwriting" (str kind) "handler for:" id))) ;; allow it, but warn. Happens on figwheel reloads.
(swap! kind->id->handler assoc-in [kind id] handler-fn)
diff --git a/src/re_frame/std_interceptors.cljc b/src/re_frame/std_interceptors.cljc
index 7102ec9..c447ce6 100644
--- a/src/re_frame/std_interceptors.cljc
+++ b/src/re_frame/std_interceptors.cljc
@@ -2,10 +2,11 @@
"contains re-frame supplied, standard interceptors"
(:require
[re-frame.interceptor :refer [->interceptor get-effect get-coeffect assoc-coeffect assoc-effect]]
- [re-frame.loggers :refer [console]]
- [re-frame.registrar :as registrar]
- [re-frame.db :refer [app-db]]
- [clojure.data :as data]))
+ [re-frame.loggers :refer [console]]
+ [re-frame.registrar :as registrar]
+ [re-frame.db :refer [app-db]]
+ [clojure.data :as data]
+ [re-frame.cofx :as cofx]))
;; XXX provide a way to set what handler should be called when there is no registered handler.
@@ -33,9 +34,9 @@
context)
:after (fn debug-after
[context]
- (let [event (get-coeffect context :event)
- orig-db (get-coeffect context :db)
- new-db (get-effect context :db ::not-found)]
+ (let [event (get-coeffect context :event)
+ orig-db (get-coeffect context :db)
+ new-db (get-effect context :db ::not-found)]
(if (= new-db ::not-found)
(console :log "No :db changes caused by:" event)
(let [[only-before only-after] (data/diff orig-db new-db)
@@ -62,10 +63,7 @@
:id :trim-v
:before (fn trimv-before
[context]
- (->> (get-coeffect context :event)
- rest
- vec
- (assoc-coeffect context :event)))))
+ (update-in context [:coeffects :event] subvec 1))))
;; -- Interceptor Factories - PART 1 ---------------------------------------------------------------
@@ -91,8 +89,8 @@
:before (fn db-handler-before
[context]
(let [{:keys [db event]} (:coeffects context)]
- (->> (handler-fn db event)
- (assoc-effect context :db))))))
+ (->> (handler-fn db event)
+ (assoc-effect context :db))))))
(defn fx-handler->interceptor
@@ -153,7 +151,7 @@
(let [path (flatten args)
db-store-key :re-frame-path/db-store] ;; this is where, within `context`, we store the original dbs
(when (empty? path)
- (console :error "re-frame: \"path\" interceptor given no params" ))
+ (console :error "re-frame: \"path\" interceptor given no params"))
(->interceptor
:id :path
:before (fn
@@ -272,9 +270,9 @@
;; if one of the inputs has changed, then run 'f'
(if changed-ins?
- (->> (apply f new-ins)
- (assoc-in new-db out-path)
- (assoc-effect context :db))
+ (->> (apply f new-ins)
+ (assoc-in new-db out-path)
+ (assoc-effect context :db))
context)))))
diff --git a/src/re_frame/subs.cljc b/src/re_frame/subs.cljc
index b6c65c3..fd5c970 100644
--- a/src/re_frame/subs.cljc
+++ b/src/re_frame/subs.cljc
@@ -87,7 +87,9 @@
"Returns a new version of 'm' in which 'f' has been applied to each value.
(map-vals inc {:a 4, :b 2}) => {:a 5, :b 3}"
[f m]
- (into {} (for [[k val] m] [k (f val)])))
+ (into (empty m)
+ (map (fn [[k v]] [k (f v)]))
+ m))
(defn- deref-input-signals