Fork me on GitHub
#clojurescript
<
2018-01-20
>
ajs00:01:21

I don't think cljsbuild would simultaneously look at two profiles

ackerleytng08:01:25

clojurescript is strangely not executing the reset! in this function... anyone knows why?

(defn do-plot
  [map-object markers-atom data]
  (let [markers (map (partial do-build-marker map-object) data)]
    ;; Removing this console.log will prevent markers from being plotted at all
    ;;   Compiler overoptimization?
    (.log js/console (clj->js [:do-plot-data data markers]))
    (map gmap-marker-remove @markers-atom)
    (reset! markers-atom markers)))

ackerleytng08:01:02

i'm using create-class in reagent because i've to first render some div before calling google's api on it to draw a map

rauh08:01:11

@ackerleytng Pretty sure reset! will be run unless something else throws an exception

rauh08:01:40

Note that map is lazy, so in case you rely on side effects you should use something else

rauh08:01:51

like doseq or mapv

ackerleytng08:01:57

i do rely on side effects.

rauh08:01:14

That'd explain the first comment, since clj->js will realize the lazy seq.

ackerleytng08:01:55

@rauh thanks soooo much!!

ackerleytng08:01:03

wait in that case, why didn't reset! force the map in let to execute?

rauh08:01:31

@ackerleytng A lazy seq is just an object. Like any other CLJS datastructure like lists or vectors. Unless you "request" an element nothing will realize the lazy seq

rauh08:01:07

reset will happily just change the atom to point to the lazy seq.

ackerleytng08:01:19

i see. thanks so much once again!

Jakub Holý (HolyJak)08:01:04

Hello! Please, how do I call an npm module from my node cljs 1) without including it in the resulting source bundle and 2) without risking that :optimizations :advanced will screw it up? I guess I could just (def aws (js/require "aws-sdk")) (.describeEnvironments (aws/ElasticBeanstalk. ...) ...) but that could by changed by advanced optimizations, so I perhaps need to include an extern file or use the automatic externs detection. Perhaps I could add to my project.clj [cljsjs/aws-sdk-js "2.94.0-0"] without actually using it anywhere, just to make its externs visible to the compiler? Or use cljs-oops for the calls, avoiding the risk of changes by :advanced? (I assume that the new npm modules integration isn't suitable because it also includes the module's code in the compiled source bundle, but I might be wrong) (Context: I am writing an AWS Lambda function. It has aws sdk node module pre-installed in the execution environment in so I don't need and don't want to include it.) Thank you!

carkh09:01:54

is there any way to prevent the compiler to add that line "#!/usr/bin/env node" to my compiled javascript for a node target ?

carkh09:01:48

and where the heck can we find a list of the goog closure defines ... ><

carkh09:01:58

nodejs could be used from windows ... or maybe from node-webkit as is the case from me... that first line could be added as part of a build process... and is rather harder to remove in the context of figwheel developement

thheller09:01:41

{:hashbang false} in the compiler options I believe

carkh09:01:54

ah ! thank you !

carkh10:01:48

How bad is it to trick cljs.core by setting *target* to "nodejs" from my code ? My problem is that I want to use js->clj , but this only works with a target of :nodejs under node-webkit ... and I can't/don't want to really target nodejs because it's now causing all kind of troubles with figwheel... that's because we're now assuming that the files are loaded from the file system rather than from a web server

carkh10:01:04

and of course figwheel, the repl and i guess cider will collectively complain, loudly

sggdfgf16:01:45

hi, how would you simplify '(aget obj name)' ? would '(name obj)' work?

darwin16:01:47

@faxa `(.-name obj)` but that likely won’t survive under :advanced compilation

darwin16:01:04

depends if name was covered by externs or not

darwin16:01:22

wait, is name a dynamic string in your case?

sggdfgf16:01:26

@darwin it is var with string inside

sggdfgf16:01:00

I just copy pasted it onto quotes here

darwin16:01:00

ok, then scrap my message

sggdfgf16:01:27

I guess you can not simplify it then?

darwin16:01:55

you can write it using goog.object/get

darwin16:01:53

or use cljs-oops library if you don’t mind adding another dependency

darwin16:01:13

with cljs-oops: (oget+ obj name)

mikerod17:01:17

@faxa quite a bit of depth on that subject @ https://clojurescript.org/news/2017-07-14-checked-array-access if you are interested

mikerod17:01:53

But I think the main storyline is that aget is/was often abused for js field access when it wasn’t really intended for that purpose

mikerod17:01:06

and Cljs may be pushing for further optimizations on its actually intended purpose - array access

Jakub Holý (HolyJak)18:01:59

Anyone knows how to use an npm modul from node cljs without including it in the gcc-produced source bundle and without advanced optimizations wreaking havoc on the calls to it? Thx!

theasp18:01:23

I don't think advanced is recommended for node, but I could be wrong

Jakub Holý (HolyJak)18:01:42

Normally it isnt needed but I am creating an AWS Lamda function so minimization is important

lilactown19:01:07

how do I convince figwheel or cljsbuild to install my npm dependencies?

lilactown19:01:57

it installed once (I think after running lein figwheel?), but after adding additional dependencies, it will not update the package.json or even install the earlier ones after deleting node_modules

lilactown19:01:10

I have :install-deps true in my compiler config as well

lilactown19:01:21

OK, I figured it out - I was trying to install a version of a library that didn’t exist

lilactown19:01:47

I’m stuck on another problem now. I’m trying to use the “glamorous” library

lilactown19:01:20

I’m getting this error in my browser when I run figwheel:

Uncaught Error: Undefined nameToPath for glamorous

lilactown19:01:53

I’m requiring it like so:

(:require
   [reagent.core :as reagent]
   glamorous)

johnj19:01:34

What's clojurescript version of async/await?

lilactown19:01:04

the core.async library

justinlee19:01:59

@U4R5K5M0A specifically go is like async and <! is like await

justinlee19:01:47

at least in terms of programmer ergonomics. under the covers they are totally different

lilactown19:01:57

:thinking_face: other modules I’ve installed from NPM - e.g. React - seem to be working fine

lilactown19:01:26

except for glamor and glamorous

lilactown19:01:46

dev:cljs.user=> (require 'left-pad)
nil
dev:cljs.user=> (require 'glamorous)
#object[Error Error: goog.require could not find: glamorous]
   figwheel$client$file_reloading$figwheel_require (jar:file:/Users/will/.m2/repository/figwheel/figwheel/0.5.14/figwheel-0.5.14.jar!/figwheel/client/file_reloading.cljs:179:30)
nil
😩

lilactown19:01:35

$ ls node_modules | grep glam
glamor
glamorous

Alex H19:01:24

fwiw, I've had much more luck with shadow-cljs when it comes to npm modules

Alex H19:01:41

had a similar issue with e.g. apollo-client and with emotion

Alex H19:01:52

they both worked out of the box with shadow-cljs

Alex H19:01:26

can't say I've tried glamorous in particular, though

lilactown19:01:24

😩 more build tools to learn

Alex H19:01:50

I think, fundamentally, google closure compiler can't cope with a fair number of import/export/etc syntax used in npm modules

Alex H19:01:07

which is why they don't really work properly with the "normal" cljs build tools

Alex H19:01:24

whilst shadow-cljs transpiles node modules before using them

lilactown20:01:38

I’m just not sure that I want to take the time to use shadow-cljs

lilactown20:01:41

I’m trying to help my team get spun up on developing in Clojure(Script) and we’re just getting comfortable using figwheel. there’s also lots of nice templates out there, so I don’t really have to focus as much on getting things like REPL integrations (e.g. CIDER, proto-repl) working

lilactown20:01:24

if it was me, I would take a week to learn how to configure shadow-cljs for my use case. but it’s taking a week to learn shadow-cljs (while not getting work done), and then spending 3 weeks helping everyone else learn it

lilactown20:01:43

I’m frustrated >_<

lilactown20:01:28

I wish I could get more info on how it’s trying to resolve the modules

thheller20:01:21

@lilactown I could tell you exactly how shadow-cljs does it but for CLJS i don’t know exactly myself unfortunately

thheller20:01:49

in theory it is looking at node_modules/glamorours/package.json main entry and then loads that file

lilactown20:01:01

🙃 modifying the package.json of glamorous fixed it

lilactown20:01:24

I removed jsnext:main and module fields from the package.json, leaving only main, and it worked

lilactown20:01:35

this seems to be a bug with CLJS’ module resolution

mac0102120:01:11

I'm struggling a little with the cljs API. I have a .cljs file containing a series of forms on my classpath and want to obtain the corresponding javascript as a string. I can get it through the analyzer, but don't know how to get the javascript emitted:

(with-core-cljs nil (fn []
                        (analyze-file "us/quartyard/wat.cljs")
                        (println(all-ns)) ;; prints essentially what I expect.
                        (now what???)))

Any help would be most appreciated.

lilactown21:01:30

@alex340 you said you have used emotion with cljs? How was it?

Alex H21:01:10

well, I have a tiny macro and I do (defstyled :div "some css strings...")

Alex H21:01:19

I'm happy with that

Alex H21:01:42

interpolations are just (defstyled :div "bla " #(:color %) ";")

Alex H21:01:45

or similar

Alex H21:01:50

well, (defstyled styled-div :div ...) rather, forgot the component name in those examples.

lilactown21:01:34

Have you used it with ssr at all?

Alex H21:01:04

no, haven't tried (or even thought about it)

lilactown22:01:03

:thinking_face: seems like not many people use cljs on the server side

Alex H22:01:42

well, in my case my day job and any of javascript/clojurescript/etc have 0 overlap

Alex H22:01:51

so SSR isn't exactly on my list of priorities 😛

lilactown22:01:56

fair enough! 😄

lilactown22:01:32

I kind of wish I worked in an area that didn’t require any js at all

thheller22:01:40

me too 😉

lilactown22:01:38

alas, web dev is too good to me right now