Fork me on GitHub
#clojurescript
<
2019-08-01
>
savaki01:08:57

I know there must be a way to do this simply, but can't think of it

savaki01:08:13

(def values ([1 2] [3 4] [5 6]))

savaki01:08:27

What I'd like to get back is ([1 3 5] [2 4 5])

savaki01:08:41

Does anyone have an idea what the incantation might be?

dpsutton02:08:13

(map vector values)

yuhan03:08:46

* (apply map vector values) since it uses the multiple-coll arity of map

✔️ 8
jakuzure09:08:44

hi, I'm having trouble connecting cider to shadow-cljs' nrepl. in theory I should be able to cider-connect and then just eval my expressions right there, right? assuming it has to do something to do with this error, but spacemacs says I have the newest version of cider apparently

thheller09:08:39

@shin which cider-nrepl version do you have in shadow-cljs.edn? or project.clj/deps.edn depending on what you use?

jakuzure09:08:48

@thheller updated it to the beta mentioned in the error now, still doesn't seem to work though

thheller09:08:30

and what is the error now?

jakuzure09:08:08

@thheller says I need nrepl 0.4.4 or newer, but I can't nrepl in any dependencies

thheller10:08:53

just add [nrepl "0.6.0"]?

thheller10:08:03

and remove tools.nrepl in case you have that

thheller10:08:29

I don't know enough about cider so I can't help any further

jakuzure10:08:56

alright, thank you anyway 🙂 cljs is not so fun without a repl though

thheller10:08:05

I know that many people use cider with shadow-cljs so it should work. no clue how current this is but maybe it helps? https://shadow-cljs.github.io/docs/UsersGuide.html#cider

jakuzure10:08:12

will check it out!

scknkkrer10:08:07

Are there any Electron Project Template for Clojurescript ?

scknkkrer11:08:56

They are not updated. Also, I think they are abondened.

manutter5111:08:56

I would still give them a try. I think Electron development in Clojure is generally declining though. If I were building a desktop app in Clojure I’d look at cljfx (https://github.com/cljfx/cljfx).

scknkkrer12:08:39

What about sharing a business-logic and UI with your web and mobile ?

manutter5112:08:30

I would try either descjop or lucmartens/cljs-electron and see if they do the job.

scknkkrer13:08:11

Thank you, sir. 😇

tianshu10:08:18

@shin hi the current doc of how to use cider with shadow-cljs is outdated. since there's a built-in support. You can use C-c M-j launch a cljs repl. cider will ask you to select a repl type. then you just select shadow, the all things works.

tianshu10:08:33

@thheller I want to update the cider section of shadow-cljs document, if there's no maintainer. using cider with shadow is much easier now.

jakuzure10:08:13

I noticed that my browser closes the shadow-cljs connection after a few seconds at work, could that be part of my problem?

tianshu10:08:46

you mean few seconds?

jakuzure10:08:46

yeah, a little error pops up telling me the connection to shadow was closed

tianshu10:08:06

is the connection ever succeed?

tianshu10:08:58

that is a websocket connection, you can check in browser console.

jakuzure10:08:22

I can load the page and do stuff, it just doesn't update on changes, but maybe the connection never worked: WebSocket connection to '<ws://xxx:9630/ws/worker/app/c0ce03b9-eebd-4c4b-988d-e96f3029881e/dc640c5b-3250-4969-946f-a0e5f9f4a472/browser>' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT

thheller13:08:08

shadow-cljs by default tries to connect to the same host the original page was loaded from

thheller13:08:13

which target are you using?

thheller13:08:55

if you run behind a proxy or on a different host you might need https://shadow-cljs.github.io/docs/UsersGuide.html#_proxy_support

jakuzure10:08:34

so that would be why the repl doesn't work either?

Daw-Ran Liou16:08:24

Hi, I found a case where :advanced compilation results in “TypeError: l.C is not a function,” which is similar to what [this link](https://github.com/yogthos/clojure-error-message-catalog/blob/master/cljs/uncaught-typeError-name.call-is-not-a-function.md) describes. In my case, I.C() is compiled from a javascript interop form (.val snapshot). I can provide more details if needed. Is .val shadowing any cljs.core function like the link suggests? Eventually I got around the issue by calling the .toJSON method to get around it.

lilactown16:08:07

@dawranliou is snapshot an external JS object?

lilactown16:08:24

aka .val should be valid even after advanced optimizations

lilactown16:08:38

then you should notate it as such: (.val ^js snapshot)

lilactown16:08:22

that will prevent optimizations from turning the .val into some single-letter method

Daw-Ran Liou16:08:54

I definitely missed the ^js notation. Thanks.

Daw-Ran Liou16:08:39

Is it generally a good idea to put ^js everywhere I want to call a method on a js object?

lilactown16:08:20

you should try turning on infer-externs first and seeing if you get any warnings

dnolen16:08:26

and you generally only need to hint once inside fn bodies

dnolen16:08:32

externs should be inferred from usage

dnolen16:08:44

if for some reason it doesn't work then file a bug in JIRA

Daw-Ran Liou16:08:25

Ok let me try everything one at a time. Thanks @lilactown @dnolen!

Daw-Ran Liou16:08:00

I’m using shadow-cljs and once I started using {:infer-externs :auto} I saw the warnings. Adding ^js does solve the problem, so no bugs there. 🙂

👍 8
dpsutton17:08:07

our webapp has <script src=cdn/Chart.js> and uses this in cljs as js/Chart. However doo with chrome-headless lacks this script when it runs our test so we cannot include test files that require our usage of charts. Does anyone know off hand how to modify the page that chrome headless will eventually load?

dpsutton18:08:34

solution: :doo {:karma {:config {"customContextFile" "resources/chrome-headless-testrunner.html"}}} and copying and modifying the custom context file that karma uses: https://github.com/karma-runner/karma/blob/master/static/context.html

Derrick19:08:51

anyone here familiar with react native in cljs and pagination?

dnolen19:08:21

@dmateja724 there's also a React Native channel #cljsrn if you don't get a response here

Derrick19:08:26

@dnolen thanks :thumbsup:

jsa-aerial21:08:19

I'm trying to understand how cljs.js/load-analysis-cache! behaves (or is supposed to behave) in a couple different scenarios. Originally I was using a trick/technique described by (I'm pretty sure) @mfikes . It uses a macro: (defmacro analyzer-state [[_ ns-sym]] '~(get-in @env/compiler [:cljs.analyzer/namespaces ns-sym]))` and then defines a state var (def state (cljs.js/empty-state)) and then it is used, for example, by (cljs.js/load-analysis-cache! state 'aerial.hanami.core (analyzer-state 'aerial.hanami.core))

jsa-aerial21:08:10

That works fine, but can take a fair amount of time in various cases. So, looking around it seemed that if the actual pre-generated cache, in this case the core.cljs.cache.json file content, is passed to load-analysis-cache! it would just take the already computed result and use it. But it seems to behave in the same way as using the 'analyzer-state' macro. Am I totally in the weeds on this??

mfikes21:08:31

@jsa-aerial What are you trying to understand? (It isn’t clear to me what question you have.)

jsa-aerial22:08:24

Take the content of a cache file, feed it to read-string and then pass it to load-analysis-cache!, is it supposed to be used as is to update the compiler state?

jsa-aerial22:08:28

When I do this, it seems to recompute the compiler analysis from the name space that's passed and not use the cache content passed

jsa-aerial22:08:05

Put another way, it takes as much time passing the precomputed and saved cache content as when giving it the 'analyzer-state' variation

jsa-aerial22:08:53

These three variations seem to behave in exactly the same way: The analysis is run from scratch

mfikes22:08:15

@jsa-aerial In both cases, data is loaded into an atom. So the question becomes: How fast can you load data into a map? When using a macro to dump a literal map into your generated code, this will have roughly the same perf as if you read Transit-encoded data to obtain that map.

jsa-aerial22:08:18

Well, this is more than loading into a map - I mean it takes 20 seconds or so

mfikes22:08:03

It sounds like you are saying your loaded cache is not being used

jsa-aerial22:08:20

It certainly seems that way, yes.

jsa-aerial22:08:10

It is very strange - you can pass nil (or indeed, not pass any 3rd arg) and the results are the same

mfikes22:08:36

I’m AFK, but take a look at the logic surrounding the *loaded-libs* var in cljs.js

jsa-aerial22:08:39

The other thing is - once it is done, things just work as expected. You can eval-str stuff that uses things from the ns, you can define new funcs in the ns and use them, etc. etc

mfikes22:08:46

There’s really no magic here. Loading the analysis cache is just that—it is not the same as requiring a namespace and loading JS, etc

jsa-aerial22:08:56

Looking at the source for load-analysis-cache! it is indeed a simple swap. But when I run this interactively (at repl via figwheel) it does indeed seem like it is loading the namespace along with all its requires. Maybe this is some odd/toxic interaction with figwheel?

mfikes22:08:37

Are you loading the analysis cache for a given namespace, followed by requiring that namespace?

jsa-aerial22:08:46

the reverse - namespaces are required and only then are the analysis caches loaded.

mfikes22:08:42

If you want to optimize the situation where you require pre-compiled namespaces, then your *load-fn* implementation can call back with the JavaScript and analysis cache.

mfikes22:08:46

If you do that, then cljs.js calls load-analysis-cache! with the the analysis cache you supply: https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/js.cljs#L325

jsa-aerial22:08:43

Yeah, I was looking into the *load-fn* usage scenario. When /where should this be bound? I know eval-str opts can take it, but is there a 'global' scenario?

mfikes23:08:24

If you have a static load function, you could conceivably just set! it

jsa-aerial23:08:39

I'm becoming pretty convinced that the weird behavior I see has something to do with some interaction between figwheel, piggyback, and /or cljs-repl

mfikes22:08:43

(You can use it as an optimization in certain situations when you know other stuff is already loaded and you just need the analysis cache to additionally be loaded.)

jsa-aerial22:08:36

That's exactly what I want - the optimization situation

jsa-aerial22:08:56

Looking at the source for load-analysis-cache! it is indeed a simple swap. But when I run this interactively (at repl via figwheel) it does indeed seem like it is loading the namespace along with all its requires. Maybe this is some odd/toxic interaction with figwheel?