Fork me on GitHub
#portal
<
2022-03-30
>
Carlo00:03:52

I'm noticing js objects are a bit unwieldy to visualize in portal. Is there anything that could be done @djblue?

Carlo00:03:30

does this do the recursive transformation too?

Carlo00:03:45

I was trying with:

(defn obj->clj
  [obj]
  (if (goog.isObject obj)
    (-> (fn [result key]
          (let [v (goog.object/get obj key)]
            (if (= "function" (goog/typeOf v))
              result
              (assoc result key (obj->clj v)))))
        (reduce {} (.getKeys goog/object obj)))
    obj))
from the same answer, but it still remains unwieldy

djblue00:03:59

what aspect seems to be unwieldy?

Carlo00:03:24

Mainly the fact that I continue to get opaque representations like:

#object[malli.core.t_malli$core61795]
instead of honest-to-god maps 😂

djblue00:03:16

I wonder if that object is a function? :thinking_face:

Carlo00:03:51

I don't think it is, it should be a malli schema

Carlo00:03:20

this is the partially translated structure:

{:args [2 3],
 :schema #object[malli.core.t_malli$core61795],
 :value "abcd", 
 :output #object[malli.core.t_malli$core61451]}

djblue00:03:07

If they expose a concrete type, you could extend datafy to it

djblue00:03:23

Then as part of the js->clj expansion, call datafy first

Carlo00:03:13

I will have to read up on datafy/nav, never used them yet

Carlo00:03:20

I guess I want something like:

(extend-protocol Datafiable
  js/KeyboardEvent
  (datafy [this] (js->clj+ this)))
but where do I find the name of the object? (like js/KeyboardEvent here)

djblue01:03:58

My best guess is that there is a deftype in the malli ns you can reference

djblue01:03:03

Yeah, I don't many concrete types in that file