Fork me on GitHub
#shadow-cljs
<
2019-08-22
>
Aklscc07:08:18

hey, guys. I use clojurescript to call some javascript library function, but this will make this in the called function invalid. Is it relative to the compiler? @thheller

thheller07:08:06

how do you call it?

thheller07:08:40

(.thatFn the-object 1 2 3) will keep the-object as this?

thheller07:08:34

.bind and other tricks don't work so well with CLJS currently

Aklscc07:08:42

No, the bare javascript function must call by ((.-thatFn obj) arg1 arg2)

thheller07:08:25

why not (.thatFn obj arg1 arg2)? whats the point of getting the fn off the object first?

Aklscc07:08:25

It's npm library for javascript.

thheller07:08:29

you are not calling (obj.thatFn)(arg1, arg2) in JS either?

Aklscc07:08:48

(.-fn obj arg1 arg2) I also try it, but doesn't work too.

thheller07:08:02

remove the -

thheller07:08:20

.-fn is short for getting that property`. (.fn ...) is short for calling that fn

Aklscc07:08:10

(.-fn obj) will get the function, so the first way doesn't matter, I have verified it.

thheller07:08:02

yes exactly. (.-fn obj) will GET the function. (.fn obj) will CALL the function

👍 8
Aklscc07:08:26

I know, thank you. You are right!

Charles17:08:26

Hi everyone. I'm trying to learn clojurescript to create an AWS lambda, but I'm having trouble getting a REPL working in emacs/spacemacs. I create REPL via cider-jack-in-clojurescript and see [nREPL] Starting server via npx shadow-cljs -d nrepl:0.6.0 -d cider/piggieback:0.4.1 -d refactor-nrepl:2.5.0-SNAPSHOT -d cider/cider-nrepl:0.22.0-beta11 server. After Select ClojureScript REPL type: node, I see [nREPL] Direct connection to localhost:37269 established, but I get an error Unhandled java.lang.AssertionError Assert failed: (keyword? repl-env). I'm using version 2.8.51, node 10.16.3, and spacemacs [email protected].

Charles18:08:10

My shadow-cljs-edn:

{:source-paths ["src"]
 :dependencies []
 :builds {:app {:target :node-library
                :exports {:handler test.main/handler}
                :output-dir "target"
                :output-to "target/main.js"}}}

David Pham18:08:52

You need to add the dependencies to cider as well

David Pham18:08:43

And you also need piggieback

David Pham18:08:58

This is how I got it working

Charles19:08:35

I have cider-nrepl and piggieback installed. The repl seems to work if I choose custom and do (shadow/watch :app) (shadow/node-repl :app)

superstructor19:08:42

Is there a way to print out the deps.cljs :npm-deps dependency tree ?

mynomoto19:08:18

Hi, I'm having trouble with a react-native project, expo is trying to connect to the wrong websocket because it is getting the wrong lan ip. How can I override the ip being used?

thheller19:08:45

@superstructor no. there is no tree. its a flat map but you can use npm list or so after they are installed

superstructor23:08:01

ok thanks, but is there a way to see what jar/deps.cljs each dependency comes from ?

thheller06:08:23

you can do this

(->> (ClassLoader/getSystemResources "deps.cljs")
     (enumeration-seq))

thheller06:08:59

then just slurp and read them

superstructor06:08:49

:thumbsup: Thanks. Is this something you'd be interested in being part of the shadow-cljs command line or is it better for me to add it to something like lein-shadow (i.e. build tool problem) ?

thheller06:08:21

dunno what do you want to do with it?

thheller06:08:52

in shadow-cljs package.json is the source of truth. deps.cljs stuff is only added if it is not already in package.json

superstructor07:08:48

So for example in re-frame-10x there are some important transitive deps: https://github.com/Day8/re-frame-10x/blob/master/src/deps.cljs

superstructor07:08:11

Then I have some other closed-source libs that also add transitive deps.

superstructor07:08:22

So my thinking was it would just be good to see where these deps came from.

superstructor07:08:37

Like, if you wanted to update one and not duplicate it in the current project.

thheller07:08:41

hmm yeah sounds useful

superstructor07:08:54

It's not urgent, so have a think about it. If you think its not the responsibility of shadow-cljs itself I'm happy to add it to lein-shadow.

thheller07:08:59

you could create a function that does that and run it via shadow-cljs run some.util/show-npm-deps

thheller07:08:29

doesn't need anything special from shadow-cljs so it would work with other tools too

superstructor07:08:11

Yeah could do the same with lein plugin. :thumbsup:

teawaterwire20:08:44

we have a module that represents one namespace, we're pulling a function from a npm package - it works fine on the dev environment but once we build the app we have this error Uncaught ReferenceError: $jscomp is not defined when calling toAscii

thheller21:08:48

do you not use :advanced? that name shouldn't exist anymore?

thheller21:08:19

which build target is this? $jscomp is used by the closure compiler for polyfills.

teawaterwire22:08:22

build target is browser so maybe it's just because we dont' have the latest version of shadow ? (ping @UCK2PHQ59 )

thheller22:08:25

can you tell which part of the code is trying to use $jscomp?

teawaterwire22:08:10

yeah it seems to be when calling that

thheller22:08:49

try using shadow-cljs release app --pseudo-names

thheller22:08:58

easier to find the source that way

thheller22:08:28

but it appears to be inside some of the JS code

thheller22:08:44

:compiler-options {:output-feature-set :es6} might do it if you can live with that

thheller22:08:04

would help to know which polyfill is missing though

teawaterwire22:08:51

with --pseudo-names i get this

teawaterwire22:08:33

the namehashed fn is this one

teawaterwire22:08:33

how come we don't have this error when not lazy loading this namespace/module?

teawaterwire23:08:48

the :compiler-options {:output-feature-set :es6} worked!

aisamu21:08:32

Hi! Updating shadow-cljs from 2.8.39 to 2.8.45 (or .51) is unfortunately breaking our REPL setup on the final NPM build of our project. We checked for the usual culprits but nothing did the trick except reverting to 2.8.39. This is an :npm-module that's being consumed by a Webpack project. From JS we have

window.CLOSURE_BASE_PATH = '/javascripts' // Should match our assets location
  require('cljs/shadow.cljs.devtools.client.browser')
After the update, the REPL connects as usual but apparently cljs.core isn't loaded:
cljs.user> 3
3
cljs.user> (first [1 2])
ReferenceError: cljs is not defined
    at eval (eval at shadow$cljs$devtools$client$browser$global_eval (webpack-internal:///./build/cljs/shadow.cljs.devtools.client.browser.js), <anonymous>:1:1)
    at eval (<anonymous>)
    at Object.shadow$cljs$devtools$client$browser$global_eval [as global_eval] (webpack-internal:///./build/cljs/shadow.cljs.devtools.client.browser.js:878:16)
    at eval (webpack-internal:///./build/cljs/shadow.cljs.devtools.client.browser.js:887:44)
[...]
Is there something else we could try? Thanks!

thheller21:08:07

hmm that is probably caused by the introduction of the global-eval fn. https://github.com/thheller/shadow-cljs/commit/1470c6d2d06195d01ba2b486ef6f730c36b51840

thheller21:08:15

hmm not sure what to do about the. I introduced the global-eval to fix another issue

thheller21:08:20

you could try copying the current browser.cljs https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/cljs/devtools/client/browser.cljs and just replacing the #(global-eval .. with (js/eval ...

thheller21:08:08

seems weird this doesn't work though. I thought I ensured the npm-modules properly exports to global

thheller21:08:30

too tired to think about that now. if you open an issue I'll take a look over the weekend

👌 4
aisamu14:08:47

https://github.com/thheller/shadow-cljs/issues/550 Please let me know if you need anything else. (Testing the global-eval substitution is still queued up, trying to find a breach on the schedule) Thanks again!

aisamu22:08:21

Will give that a try, thanks!