aaronc / freactive

High-performance, pure Clojurescript, declarative DOM library
http://documentup.com/aaronc/freactive
Eclipse Public License 1.0
387 stars 27 forks source link

Changed `rx-debug` to `debug-rx` as it's actually called. #15

Closed luxbock closed 10 years ago

luxbock commented 10 years ago

Maybe it should be the other way around? I'm also wondering if rather than having debug-rx be a wrapper around a call to rx, it should rather act like rx does but also output debug-info to the console? It's a small change but I think adding -debug at the end of rx to turn on debugging would be easier than adding a separate wrapper around it.

luxbock commented 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#)))
aaronc commented 10 years ago

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!