clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Jean 2020-12-22T18:23:50.445100Z

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

thelittlesipper 2020-12-22T19:02:14.445400Z

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

thelittlesipper 2020-12-22T19:09:53.450100Z

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.

lilactown 2020-12-22T19:17:46.450400Z

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
lilactown 2020-12-22T19:18:15.450600Z

this is equivalent to the JS code:

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

thelittlesipper 2020-12-22T19:20:11.450900Z

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

p-himik 2020-12-22T19:32:28.451200Z

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.

p-himik 2020-12-22T19:34:22.451400Z

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

👍 2
p-himik 2020-12-22T19:34:44.451600Z

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