mirror of
https://github.com/status-im/status-react.git
synced 2025-01-11 03:26:31 +00:00
Tracing of nested fx handlers on :trace logging level
This commit is contained in:
parent
6d43f34cf8
commit
011de1b8ae
@ -10,6 +10,9 @@
|
|||||||
(fn [cofx# [_# ~@argsyms]] (~name cofx# ~@argsyms))))
|
(fn [cofx# [_# ~@argsyms]] (~name cofx# ~@argsyms))))
|
||||||
events))
|
events))
|
||||||
|
|
||||||
|
(defn- fully-qualified-name [sym]
|
||||||
|
(str *ns* "/" (name sym)))
|
||||||
|
|
||||||
(defmacro defn
|
(defmacro defn
|
||||||
"Defines an fx producing function
|
"Defines an fx producing function
|
||||||
Takes the same arguments as the defn macro
|
Takes the same arguments as the defn macro
|
||||||
@ -50,6 +53,18 @@
|
|||||||
(clojure.core/defn ~(with-meta name m)
|
(clojure.core/defn ~(with-meta name m)
|
||||||
([~@argsyms] (fn [cofx#] (~(with-meta name m) cofx# ~@argsyms)))
|
([~@argsyms] (fn [cofx#] (~(with-meta name m) cofx# ~@argsyms)))
|
||||||
([cofx# ~@args]
|
([cofx# ~@args]
|
||||||
|
(when js/goog.DEBUG
|
||||||
|
(when (taoensso.timbre/level>=
|
||||||
|
:trace
|
||||||
|
(:level taoensso.timbre/*config*))
|
||||||
|
(println
|
||||||
|
(clojure.string/join
|
||||||
|
(concat
|
||||||
|
(repeat
|
||||||
|
(deref status-im.utils.handlers/handler-nesting-level)
|
||||||
|
"│ ")
|
||||||
|
["├─"]))
|
||||||
|
~(str (clojure.core/name name) " " *ns*))))
|
||||||
(if (and (map? cofx#)
|
(if (and (map? cofx#)
|
||||||
(not (nil? (:db cofx#))))
|
(not (nil? (:db cofx#))))
|
||||||
(let [res# (let [~cofx cofx#] ~@fdecl)]
|
(let [res# (let [~cofx cofx#] ~@fdecl)]
|
||||||
@ -61,9 +76,9 @@
|
|||||||
m#
|
m#
|
||||||
(when (and (map? k#)
|
(when (and (map? k#)
|
||||||
(contains? k# :db))
|
(contains? k# :db))
|
||||||
(throw (js/Error. (str "fx/defn's result is used as fx producing function in " ~name))))
|
(throw (js/Error. (str "fx/defn's result is used as fx producing function in " ~(fully-qualified-name name)))))
|
||||||
(get m# k# nil)))))
|
(get m# k# nil)))))
|
||||||
res#)
|
res#)
|
||||||
(throw (js/Error. (str "fx/defn expects a map of cofx as first argument got " cofx# " in function " ~name))))))
|
(throw (js/Error. (str "fx/defn expects a map of cofx as first argument got " cofx# " in function " ~(fully-qualified-name name)))))))
|
||||||
~@(register-events events interceptors (with-meta name m) argsyms))
|
~@(register-events events interceptors (with-meta name m) argsyms))
|
||||||
(throw (Exception. (str "fx/defn expects a vector of keyword as value for :events key in attr-map in function " name))))))
|
(throw (Exception. (str "fx/defn expects a vector of keyword as value for :events key in attr-map in function " name))))))
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
(:require-macros status-im.utils.fx)
|
(:require-macros status-im.utils.fx)
|
||||||
(:require [status-im.ethereum.json-rpc :as json-rpc]
|
(:require [status-im.ethereum.json-rpc :as json-rpc]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
status-im.utils.handlers)
|
[status-im.utils.handlers :as handlers])
|
||||||
(:refer-clojure :exclude [merge reduce]))
|
(:refer-clojure :exclude [merge reduce]))
|
||||||
|
|
||||||
(defn- update-db [cofx fx]
|
(defn- update-db [cofx fx]
|
||||||
@ -47,6 +47,8 @@
|
|||||||
:data-source/tx and effects are handled specially and their results
|
:data-source/tx and effects are handled specially and their results
|
||||||
(list of transactions) are compacted to one transactions list (for each effect). "
|
(list of transactions) are compacted to one transactions list (for each effect). "
|
||||||
[{:keys [db] :as cofx} & args]
|
[{:keys [db] :as cofx} & args]
|
||||||
|
(when js/goog.DEBUG
|
||||||
|
(swap! handlers/handler-nesting-level inc))
|
||||||
(let [[first-arg & rest-args] args
|
(let [[first-arg & rest-args] args
|
||||||
initial-fxs? (map? first-arg)
|
initial-fxs? (map? first-arg)
|
||||||
fx-fns (if initial-fxs? rest-args args)]
|
fx-fns (if initial-fxs? rest-args args)]
|
||||||
|
@ -36,12 +36,16 @@
|
|||||||
(let [[first _] (get-coeffect ctx :event)]
|
(let [[first _] (get-coeffect ctx :event)]
|
||||||
first))
|
first))
|
||||||
|
|
||||||
|
(def handler-nesting-level (atom 0))
|
||||||
|
|
||||||
(def debug-handlers-names
|
(def debug-handlers-names
|
||||||
"Interceptor which logs debug information to js/console for each event."
|
"Interceptor which logs debug information to js/console for each event."
|
||||||
(->interceptor
|
(->interceptor
|
||||||
:id :debug-handlers-names
|
:id :debug-handlers-names
|
||||||
:before (fn debug-handlers-names-before
|
:before (fn debug-handlers-names-before
|
||||||
[context]
|
[context]
|
||||||
|
(when js/goog.DEBUG
|
||||||
|
(reset! handler-nesting-level 0))
|
||||||
(log/debug "Handling re-frame event: " (pretty-print-event context))
|
(log/debug "Handling re-frame event: " (pretty-print-event context))
|
||||||
context)))
|
context)))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user