Misc re-frame tweaks
This commit is contained in:
parent
9d533d2f23
commit
6a86431a44
|
@ -1,7 +1,7 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = tab
|
||||
indent_style = space
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
|
|
|
@ -12,6 +12,5 @@
|
|||
</value>
|
||||
</option>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (2)" />
|
||||
</component>
|
||||
</project>
|
|
@ -33,11 +33,9 @@
|
|||
: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))))
|
||||
(doseq [[effect-k value] (:effects context)]
|
||||
(if-let [effect-fn (get-handler kind effect-k true)]
|
||||
(effect-fn value))))))
|
||||
|
||||
;; -- Builtin Effect Handlers ------------------------------------------------
|
||||
|
||||
|
@ -55,7 +53,7 @@
|
|||
:dispatch-later
|
||||
(fn [value]
|
||||
(doseq [{:keys [ms dispatch] :as effect} value]
|
||||
(if (or (empty? dispatch) (-> ms number? not))
|
||||
(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
|
||||
|
|
|
@ -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)))))))))
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
[re-frame.loggers :refer [console]]
|
||||
[re-frame.registrar :as registrar]
|
||||
[re-frame.db :refer [app-db]]
|
||||
[clojure.data :as data]))
|
||||
[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.
|
||||
|
@ -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 ---------------------------------------------------------------
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue