day8 / re-frame-10x

A debugging dashboard for re-frame. X-ray vision as tooling.
MIT License
634 stars 68 forks source link

Allow 3rd party trace #149

Open mike-thompson-day8 opened 6 years ago

mike-thompson-day8 commented 6 years ago

At the moment, re-frame and reagent are the only sources of trace. How about we allow the application programmer to produce their own trace, and have it folded into the stream for later inspection.

Hmm. Strictly speaking this is a re-frame issue more than a re-frame-trace issue, I think, but it makes sense to track it here.

Perhaps have tracing macro utilities which make it even easier for programmers to produce trace.

As an example, consider this dlet macro:

;; From e.g. https://github.com/scottjad/uteal
(defmacro dlet
  "let with inspected bindings"
  [bindings & body]
  `(let [~@(mapcat (fn [[n v]]
                     (if (or (vector? n) (map? n))
                       [n v]
                       [n v '_ `(println (name '~n) ":" ~v)]))
                   (partition 2 bindings))]
     ~@body))

which allows use like:

(dlet  [a  (something :a)      ;; note use of `dlet` instead of `let`
        b  (f "hello")]
   ... )

Now imagine that dlet produced trace instead of using println . And imagine that the trace is recorded against the event handler (or subscription) in which this dlet was used. Maybe call it tlet for trace let.

kimo-k commented 1 year ago

Maybe this could be a single tap handler that observes re-frame's state.

Any macros would simply wrap parts of your code with (tap>). That could easily be its own concern, not dependent on 10x.

To record not just an evaluation, but the literal form as well, is a cool idea. I think shadow-cljs does that.

(defmacro tlet
  "let with tapped bindings"
  [bindings & body]
  `(let [~@(mapcat (fn [[n v]]
                     (if (or (vector? n) (map? n))
                       [n v]
                       [n v '_ `(tap> [(name '~n) ~v)]]))
                   (partition 2 bindings))]
     ~@body))

@mike-thompson-day8