clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2021-05-31T00:40:00.439400Z

Anyone from PenPot here?

Felipe 2021-05-31T12:18:01.442200Z

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-himik 2021-05-31T12:19:36.442300Z

Do you use self-hosted CLJS?

Felipe 2021-05-31T12:27:48.442500Z

nope! I'm just following the webpack guide

Felipe 2021-05-31T12:33:22.442700Z

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

Felipe 2021-05-31T12:33:35.442900Z

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

p-himik 2021-05-31T12:37:14.443100Z

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

Felipe 2021-05-31T12:39:17.443300Z

https://clojurescript.org/guides/webpack

p-himik 2021-05-31T12:41:09.443500Z

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

Felipe 2021-05-31T12:43:40.443700Z

I want to do both šŸ™‚ REPL for experimentation, then once I get what I want I write it to a .cljs file

p-himik 2021-05-31T12:48:54.443900Z

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.

Felipe 2021-05-31T12:50:04.444100Z

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-himik 2021-05-31T12:51:13.444300Z

Ahh, sure!

Felipe 2021-05-31T12:51:57.444500Z

cool!

7e27 2021-05-31T15:21:47.448100Z

Defining a macro like

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

p-himik 2021-05-31T15:28:29.448200Z

I suspect this is because of the last item here: https://www.clojurescript.org/about/differences#_vars_and_the_global_environment

7e27 2021-05-31T15:33:38.448500Z

ahh thanks!

Michael Jung 2021-05-31T20:56:35.456900Z

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-himik 2021-05-31T21:01:17.457100Z

Add ^js in front of the definition of navigation.

okeydoke 2021-05-31T21:07:55.458100Z

Hey @dnolen is there any way to view the recent talk you did https://2021.phillyemergingtech.com/talks/clojurescript-in-the-age-of-typescript/ ?

okeydoke 2021-06-01T08:03:05.466500Z

Ah thanks @p-himik!

Michael Jung 2021-05-31T21:11:55.458300Z

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 Jung 2021-05-31T21:16:17.458500Z

Seems to have done the trick! Thanks for the quick help @p-himik

1šŸ‘