Fork me on GitHub
#reagent
<
2018-07-26
>
p-himik10:07:24

Hello. I'm trying to use react-sortable-hoc (https://github.com/clauderic/react-sortable-hoc) in Reagent. I started just like here: https://gist.github.com/vbedegi/0329db5ff5772526a34b56d59e07d320 The problem is that my components pass CLJS maps in props. So, if my Reagent component receives something like {:a {:b 1}}, its version wrapped like in the gist receives {:a # js {:b 1}}. It looks like reagent/reactify-component + reagent/adapt-react-class do js<->cljs transformation only on one level of props.

p-himik10:07:34

Does it make any sense? What am I missing?

p-himik10:07:12

To clarify - I mentioned react-sortable-hoc only to justify the whole (-> my-component reagent/reactify-component transform reagent/adapt-react-class) pipeline. If I use identity in place of transform, the issue persists.

p-himik11:07:07

Hmm, the top-level cljs map is probably created here: reagent.impl.component/shallow-obj-to-map.

justinlee18:07:44

@p-himik I’m not sure what the motivation for the shallow conversion is, but note that you can just run`clj->js` on #js structures or mixed structures again

justinlee18:07:25

like so:

(clj->js {:a #js {:b 3}})
=> #js{:a #js{:b 3}}

justinlee18:07:51

so you could either wrap the incoming props in the implementation or you could create a helper function

justinlee18:07:37

it’s a bit annoying that you’d double convert the top-level props, but I’d be shocked if that ever really matters

justinlee18:07:57

and actually looking at the source code, passing an already converted js structure to clj->js is a no-op and the only overhead would be a function call

p-himik00:07:29

The problem is not that something is double converted. The problem is that something is not converted back.