Fork me on GitHub
#clojurescript
<
2021-05-31
>
Felipe12:05:01

hi! how do I require (using require, not :require) some lib that has a leading @ in its name? this works (ns hello-bundler.core (:require ["@urql/core" :as urql])) but how could I use a function to do the same thing?

p-himik12:05:36

Do you use self-hosted CLJS?

Felipe12:05:48

nope! I'm just following the webpack guide

Felipe12:05:22

ok, (require '["@urql/core" :as urql]) seems to work

Felipe12:05:35

I thought I had to use a symbol in the function for some reason

p-himik12:05:14

Huh. Can you link the guide? I'm just curious.

p-himik12:05:09

Ah, alright. Do you use that require in a REPL or in a compiled code?

Felipe12:05:40

I want to do both 🙂 REPL for experimentation, then once I get what I want I write it to a .cljs file

p-himik12:05:54

And that's exactly what I'm concerned about. No idea about Webpack in particular but AFAIK you can't make require work in a not self-hosted environment outside of REPL. You can still have somewhat dynamic requires with module splitting. And I think you can have proper dynamic requires but with some other tools and not the default require. But I've never done that so can't comment.

Felipe12:05:04

oh, no, I want to use require as a function for REPL-driven development, and stick to :requires in ns forms for compilation. seems alright, right?

p-himik12:05:13

Ahh, sure!

7e2715:05:47

Defining a macro like

(defmacro hmm [fun]
 `((var ~(symbol fun))))
seems to work as expected in a clojure repl, but not in clojurescript?

7e2715:05:38

ahh thanks!

Michael Jung20:05:35

Hi I’m working on a small project using react native, react navigation, reagent, re-frame, and krell. I’m having trouble getting my code to run with advanced optimizations turned on: one of the functions I call seems to get renamed. I’m using a global atom to get access to the root navigation object of react-navigation (the atom is set by react-navigation using a callback I provided). When I try to use this object, I get problems:

(.dispatch navigation (.replace StackActions "Home"))
navigation is the value from the atom and .dispatch is the problematic method. This is the error message I get:
TypeError: hc($s).Zf is not a function. (In 'hc($s).Zf(_$$_REQUIRE(_dependencyMap[2], "@react-navigation/native").StackActions.replace("Home"))', 'hc($s).Zf' is undefined)
When I manually edit the generated code and replace .Zf with .dispatch, the program works as expected. So my question is: how can I prevent that this function call is being renamed?

p-himik21:05:17

Add ^js in front of the definition of navigation.

Michael Jung21:05:55

Let me provide a little more context:

(let [navigation @!navigation]
  (.dispatch navigation (.replace StackActions "Home")))
Should I add ^js like this? (let [^js navigation @!navigation] ?

Michael Jung21:05:17

Seems to have done the trick! Thanks for the quick help @U2FRKM4TW

👍 3