Closed luxbock closed 10 years ago
I haven't tried this, but something like this should work, I think:
(defmacro debug-rx [& body]
(let [dgb-str (str "rx-debug: " (pr-str &form))]
`(let [dbg-str# ~dbg-str
res#
(binding [freactive.core/*do-trace-captures*
(fn
([] (println dbg-str# ": starting capture"))
([c#] (println dbg-str# "captured :" c#)))]
(freactive.core/rx* (fn [] ~@body) false))
invalidation-cb#
(fn [k# r#] (println dbg-str#
"notifiying invalidation watches:"
(cljs.core/keys (.-invalidation-watches res#))
"& watches:"
(cljs.core/keys (.-watches res#))))]
(freactive.core/add-invalidation-watch res# dbg-str# invalidation-cb#)
res#)))
Okay, so basically we would create an rx
at the same time with this version. The only reason I wouldn't do this is because in the generic form, this macro could be used around anything that behaves like an rx. Actually right now, this macro can also provide info on when cursors are invalidated - might be useful too.
Thanks for the proofreading!
Maybe it should be the other way around? I'm also wondering if rather than having
debug-rx
be a wrapper around a call torx
, it should rather act likerx
does but also output debug-info to the console? It's a small change but I think adding-debug
at the end ofrx
to turn on debugging would be easier than adding a separate wrapper around it.