Fork me on GitHub
#clojurescript
<
2020-06-04
>
b405:06:00

1. (resolve (symbol "max")) -> error: Argument to resolve must be a quoted symbol 2. (resolve 'max) -> working 3. (= 'max (symbol "max")) -> true 'max and (symbol "max") is same so #1 should work. but there is error. could u have any advice for me. or plz tell me any helpful link.

phronmophobic05:06:35

I think there are some work arounds by using cljs.analyzer.api/resolve https://cljs.github.io/api/cljs.analyzer.api/resolve , but it can be tricky

b405:06:13

thanks i will check it.

phronmophobic05:06:59

I’m not sure you can use cljs.analyzer.api/resolve in cljs, I think it has to be used in a clojure macro called from cljs

phronmophobic05:06:02

since the var information is only available at compile time

b405:06:22

ok. thanks your help.

e14:06:46

I compiled my cljs app into an npm module using shadow-cljs and want to call it within a JS module. This JS module has access to an object with global scope controlling URL state, and, given the architecture of the broader system, I have to use that object within my cljs code and access some methods within it. Think something to the effect of:

# my js file
mycljs.init(router) // within js module, initializing app with said needed object

...
# in my cljs file
(defn init [router]
  ... logic whatever ...
  (.changePage router "someNewUrl"))
The problem is that this ... doesn't actually work. it complains there is no such function associated with the object (and, tellingly, the name is mangled in the console error logs--it complains there is no such function http://iq.Ga  or some sort). I have no issues accessing attributes, e.g.
(.-pathname router)
so I know I am at least converting the object properly. It's just the methods that are tripping it up. So... my next thought is perhaps I need to define externs, because the cljs code is mangling the method names (I think)? I think I'm a bit uncertain because it seems like most of the things online I see about using JS modules are assuming you are running things via cljs and have access to the NPM module. I am sort of doing the reverse--compiling my cljs, calling that in regular js, and passing that function a js object. The cljs code does not know the NPM module exists at all, only that it's supposed to receive an object.

thheller15:06:41

@rbruehlman turn on externs inference. the compiler will tell you about things that are likely to be renamed and causing issues. https://shadow-cljs.github.io/docs/UsersGuide.html#externs

thheller15:06:54

in your case probably just (defn init [^js router] ...)

e15:06:14

perfect--that worked! thanks!

👍 4
pbaille16:06:43

Hello clojurians, I encountered the same problem as in https://stackoverflow.com/questions/34700857/how-to-extend-protocols-to-clojurescript-collections-generically for the past with the latest release of clojurescript. Am I supposed to duplicate implementations or is there a better way to do this ? thank you

dnolen16:06:36

@pbaille you cannot do what you do in Clojure because JavaScript doesn't have interfaces

dnolen16:06:17

btw it's better to ask Clojure(Script) questions here: https://ask.clojure.org

pbaille16:06:37

@dnolen thank you, i just wanted to be sure i was not missing something

dnolen16:06:06

one workaround is that you can extend-type default and in your implementation check to see if the thing satisfies some protocol