Fork me on GitHub
#clojurescript
<
2020-12-22
>
Jean18:12:50

Hello 🙂 What React wrapper would you recommand between reagent, uix and helix?

thelittlesipper19:12:14

reagent (& re-frame) are usually what I go with, and what I mostly see others use for react-based cljs front-ends

p-himik19:12:28

If you prefer thin wrappers then helix. If you prefer to have some nice things at the cost of more abstractions, then reagent. Can't say anything about uix - haven't used it. I almost always use reagent as well.

thelittlesipper19:12:53

How does one explode a vector into args for multi-arity js functions? I stumbled across https://stackoverflow.com/questions/41190807/in-clojurescript-how-do-i-pass-a-collections-elements-as-arguments-to-a-variab. The discussed example works just fine in my cljs repl using apply. But, I can't seem to apply (pun intended) the same logic to some other js functions like Array.push i.e. (def a (js/Array.)) (apply (.-push a) [1 2]) doesn't work for me and throws #object[TypeError TypeError: Cannot assign to read only property 'length' of function 'function push() { [native code] }'] It's moments like this where I wish cljs just supported the js spread operator i.e. ... - I don't think it's that far of a cry from the dots and dashes one already has to use for interop.

lilactown19:12:46

hmm I'm not sure about that error yet (I can repro I just don't know why) but you can also use .apply and the prototype method:

(.apply js/Array.prototype.push a (to-array [1 2]))

💯 1
lilactown19:12:15

this is equivalent to the JS code:

Array.prototype.push.apply(a, [1, 2])

thelittlesipper19:12:11

Ah, thanks! It works : - ) Forgot about the js apply function.

p-himik19:12:22

Hint: it works if you wrap (.-push a) in (.bind ... a). :)

👍 2
p-himik19:12:44

Array.prototype.push requires some this. (.-push a) is unbound.