mfikes / cljs-bean

Efficient JavaScript object interop via idiomatic ClojureScript
Eclipse Public License 1.0
306 stars 9 forks source link

How to use bean and ->clj on objects like js/Error? #90

Open introom opened 2 years ago

introom commented 2 years ago

For now, for the following code:

(def e (js/Error. "test string"))
;; 1
(bean/e) 
;; 2
(->clj/e)

1) gives

{:clojure$core$protocols$Datafiable$ #js {}, :clojure$core$protocols$Datafiable$datafy$arity$1 #object[Function]

2) gives

#object[Error Error: test string]

Would be better if it can give things like

{"message":foo,  "line":foo,  "column":foo,  "stack":foo}
mfikes commented 2 years ago

Relevant: https://clojure.atlassian.net/browse/CLJS-3014

introom commented 2 years ago

Not sure on the details. Isn't it possible to use all the possible keys from an object to form a bean? So it will work not only in the specific case of Error->map ?

mfikes commented 2 years ago

@introom One issue here is that js-keys returns an empty array when applied to a js/Error object.