Open Hendekagon opened 4 years ago
Seems similar to #76
I've experienced this as well. data coming from a callback in a separate react lib built with typescript.
Fortunately I maintain the typescript lib so I was able to workaround by converting all data to plain js objects (using Object.assign) and then both ->clj and recursive bean worked fine.
Before the workaround, object? was false and then true for the plain js objects.
Not ideal for people using 3rd party libs where they can't use the same workaround at the source. However it should be possible to write an extra fn in cljs with interop until this lib can handle typescript/react js objects.
Ran into this myself on several occasions. Worth mentioning is that not even js->clj
works on React events or native events because they are not plain objects, they are specific classes that I don't think implement the mechanisms that functions like js->clj and bean rely on to collect props into a map.
Most of the time I've used lightweight functions to transform the events to clj maps:
(defn event->map
[e]
{:type (.-type e)
:target (.-target e)
:current-target (.-currentTarget e)
:prevent-default #(.preventDefault e)
;; ... other keys if needed
})
I've tried using
->clj
with mouse events in a Reagent app with both(fn [e] (->clj e) ...)
where the fn is the handler for the event, but it doesn't convert (it remains JS object). Using->clj
on the event's.-nativeEvent
doesn't work either - what should I do ?