Fork me on GitHub
#clojurescript
<
2015-11-18
>
jslavin04:11:53

@maria: Nice talk today at clojure/conj, thank you

nathansmutz06:11:36

Mind if I ask a newbie figwheel question?

nathansmutz06:11:58

To get figwheel to pick up new dependencies, do you need to do something other than :cljs/quit, lein clean, lein figwheel ? I'm woking through the figwheel quickstart and figwheel isn't seeing sablono when I add it.

danielcompton07:11:41

@nathansmutz: you need to restart figwheel. There is an experimental command to add it from the REPL, but IIRC that is deprecated now

dmi3y09:11:47

Hi guys, we are looking for a ClojureScript guy who is also looking for a team to participate in #C09TMSH7G. Let me know if you’re interested. simple_smile

thheller09:11:28

@isak (.closest e.target ...) is not valid CLJS, try (.closest (.-target e) ...)

bensu13:11:58

@delaguardo: @isak @thheller to replace .closest you can also look for goog.dom/getAncestorByClass

bensu13:11:09

hidden Google Closure jem (everything there feels like a hidden jem simple_smile )

delaguardo14:11:59

i try to avoid not needed dependencies )

maio15:11:13

is instance? safe to use with records in ClojureScript? (sometimes) I'm getting false 😕

lvh16:11:51

delaguardo: Closure is available by default in Clojurescript

delaguardo16:11:09

not all parts

lvh16:11:20

goog.dom/getAncestorByClass is

lvh16:11:33

which parts are missing?

dnolen16:11:24

@maio sounds unlikely to me, would need a reproducer

dnolen16:11:49

@maio note that if you’re at a REPL and reloading code it’s easy to run into that problem

delaguardo16:11:26

after that you have dependency on goog.dom, without this line you can’t use it. from browser console for example

isak16:11:46

@thheller: changing from dot syntax to to normal ".-" syntax didn't do anything to help closure in advanced mode - it still garbles the closest method

isak16:11:58

and to be clear, it worked without optimizations

maio16:11:13

@dnolen: ok, that might be the problem. It's om app with record in shared state and I'm doing instance? after figwheel reload.

dnolen16:11:40

@maio yeah that won’t work

isak16:11:11

but yeah, i ended up solving it by using a library instead of using the polyfills

maio16:11:46

@dnolen: ok, thanks!

lvh16:11:04

delaguardo: The Closure library is normally just for JavaScript; it’s pretty easy to use them from the console. In fact, you use it from the console just like you would use any of your own ClojureScript code, because ClojureScript leverages Closure’s module system.

dnolen16:11:12

@maio I would move your records into another namespace or not use records if you’re set on live coding with Figwheel simple_smile

lvh16:11:58

I’m not aware of any interesting differences you’d be able to see in usage from JavaScript land between your.ns/closer and goog.dom/whatever; I certainly haven’t noticed any doing that myself

dnolen16:11:05

@honza Cider + CLJS is expert level stuff from what I’ve seen so far, very few people can get that setup to work

dnolen16:11:33

I suspect Socket REPL in 1.8 will allow tooling to unify the CLJ/CLJS REPL story

lvh16:11:48

My main successes with it have been inferior mode and figwheel’s built in nrepl

lvh16:11:01

+ sidecar if you actually want the CLJS repl of course

lvh16:11:16

it mostly works, but I can’t get test discovery to work

malch16:11:42

@dnolen: actually it’s not that bad 😊 Sure it’s not as simple as it might be, but won’t call that “expert level” either

dnolen16:11:43

@malch not saying it can’t be made to work, but as somebody who watches nearly every ClojureScript communication channel I have a good sense of how many people struggle with it and how long they struggle with it.

malch16:11:34

yeah, you are right here. The main problem, I suppose, is in a number of moving parts

dnolen16:11:07

@malch and I think it’s a big source of frustration because it “just works” with Clojure

lvh16:11:08

delaguardo: Can you clarify what production means? What compiler flags, et cetera?

delaguardo16:11:10

all dead code eliminated becouse i dont have this dependencies

delaguardo16:11:35

i cant say that my realisation of closest method is perfect, but it works)

delaguardo16:11:57

this is :simple, just for normal names

lvh16:11:40

my experience with getting stuff to work in one browser and then sending it to users has been less than perfect, plus I’m too lazy to write them in the first place

malch16:11:51

@dnolen: Was thinking for some time now about creating “CIDER cljs” template, which would serve as a starting point for cljs users

lvh16:11:15

delaguardo: I don’t understand why that’s special though; dead code gets eliminated the same way regardless of if it’s in a clojurescript ns or a goog.whatever module

lvh16:11:37

(mostly because cljs gets compiled to js before the Closure compiler does the dead code elimination

malch16:11:28

probably it’s time to start that

dnolen16:11:51

@malch yeah I think it would be a huge help

dnolen16:11:03

also not clear to me why there isn’t documentation about this somewhere

dnolen16:11:23

happy to see someone start a tooling page on the ClojureScript wiki for stuff like this

delaguardo16:11:29

@lhv: https://closure-library.googlecode.com/git-history/docs/local_closure_goog_dom_dom.js.source.html#line2033, after that line you need goog.dom.getAncestorByTagNameAndClass and Element type

malch16:11:09

If you combine that, it works

malch16:11:53

Yeah, it’s not straightforward

honza16:11:58

@dnolen Ha, thanks, now I don't feel so useless. :)

dnolen16:11:42

@malch yeah that’s a problem

dnolen16:11:02

I would like to see a tooling page on ClojureScript that describes how to do this

dnolen16:11:22

normally this isn’t a good idea, but too many people want to accomplish the same thing

dnolen16:11:05

and I’m less concerned since nREPL and Figwheel are less likely to change these days

malch16:11:56

@dnolen I was thinking that public repo would be a slightly better idea. Since anyone will be able to just run “lein new” and try it out

dnolen16:11:15

@malch it’s really not better

dnolen16:11:27

I think people understand that the wiki is now the source of truth

dnolen16:11:45

and better to collect all newcomer (and non-newcomer) information there

malch16:11:28

Ok, I hear you

dnolen16:11:40

@malch and I don’t mean to say that having a repo is bad

dnolen16:11:50

just make sure that the wiki links to the real docs

malch16:11:17

Right, ok

malch16:11:10

Will show you first draft when it’s done (if you want)

dnolen16:11:35

I’ll even try it out (gulp) 😉

snoe16:11:13

Is it possible to write an es6 generator (`function*`) in clojurescript? I miss <!! in core.async

dnolen17:11:49

@snoe: no support for that

dnolen17:11:06

es6 stuff would have to be written in JavaScript and be able to go through Closure

delaguardo17:11:53

@snoe: you can try babel for clarify whats going on in function* and repeat it in clojurescript - https://babeljs.io/repl/

chrislloyd19:11:51

hi! 👋 long time lurker. i was wondering if there had been any previous discussion about removing cljs’ dep. on goog?

martinklepsch19:11:46

@chrislloyd: as in the compiler or the closure standard library?

chrislloyd19:11:05

the standard library

martinklepsch19:11:10

Why would you want to remove the standard library (unused parts are stripped during compilation)?

martinklepsch19:11:50

I’m not aware of such discussions to answer the question simple_smile

chrislloyd19:11:42

no concrete reason, just curious if it had been discussed. seemed like from the outset an unusual dependency and kind of goes against the grain of the rest of the JS ecosystem these days

martinklepsch19:11:52

@chrislloyd: I just watched this (generally entertaining) talk that might shed some light on why goog/ closurelib is awesome: https://www.youtube.com/watch?v=gsffg5xxFQI

martinklepsch19:11:56

👏 to @nullptr for this one btw simple_smile

lvh19:11:34

Hey, is there anything special about :resource-paths when compiling ClojureScript? I’m trying to assert something about the production build in my tests, so I’m running lein cljsbuild … to produce the js file and then running lein doo to run my tests against Phantom. I have a macro to read the file as a resource (it’s a macro so that it’s read in Clojure). This works fine in development mode, but not in the test build 😕

lvh19:11:14

fortunately (?) since it’s a compile-time thing I can reproduce with just lein cljsbuild test once.

lvh19:11:46

I’m getting Caused by: java.lang.IllegalArgumentException: No implementation of method: :make-reader of protocol: #' found for class: nil which is mostly an opaque way of saying “that thing io/resource gave you was nil, so no, you can’t slurp it)

grav19:11:45

I have a js object which has a readonly maplike interface. Can I use this as a cljs map in some way, whichout converting it by hand?

noonian20:11:38

you could use extend or specify (for the constructor or specific instances) to implement the proper protocols

lvh22:11:10

Where does the compiler get its resource paths from when doing macroexpansion (in Clojure, not in the bootstrapped compiler)? Is there anything else going on with that classloader? I can’t seem to use http://clojure.data.io/resource in macros being expanded for clojurescript; it doesn’t find said resources 😞

johanatan22:11:16

@martinklepsch: Note that there is a diff between the closure libs (which @chrislloyd asked about) and the closure compiler (which @nullptr extolled).

chrislloyd22:11:34

@nullptr’s talk was excellent, btw — though i disagree with some of his justifications simple_smile

martinklepsch22:11:05

@chrislloyd: what do you disagree with? simple_smile

chrislloyd22:11:38

i see the biggest hurdle to using clojurescript in serious products being the lein + jvm + closure compiler module system + google closure libs

chrislloyd22:11:29

when asking programmers to pick up an entirely new syntax i think it’s tough having to ask them to pick up new build tools + libs

chrislloyd22:11:58

i’d love being able to use clojurescript to be as easy as using coffeescript, for instance

johanatan22:11:50

@chrislloyd: that was one point emphasized by @nullptr too

chrislloyd22:11:14

yeah, his attitude in the talk was “these things suck, but they’re ultimately good for you” which is totally reasonable. i agree that they’re good, but are additionally good from clojurescript itself.

chrislloyd22:11:06

again, loved his talk and it really clarify my own thoughts

Tim22:11:30

I was under the impression that closure was just a compiler

Tim22:11:38

but its also a whole front end library

jaen22:11:27

But you basically want to take everything away from Clojurescript that constitutes it; I don't think that's ever gonna happen. Maybe something that looks like Clojurescript enough would make more sense for you? And by that I mean this - https://github.com/Gozala/wisp

jaen22:11:53

Of course you lose things like core.async, reagent and whatnot, but you also lose the parts that you don't like.

chrislloyd22:11:46

That’s really interesting, thanks for the link. I haven’t looked at core.async, but is there an obvious reason why it doesn’t work with wisp?

kamn22:11:47

Just to add in my personal and limited experience with cljs I have only really had to worry about learning lein

jaen22:11:42

Well, wisp is not Clojure, so that's sort of a question like why C# lib won't work with Java, even though at first glance they look similar.

jaen22:11:57

It's not an implementation of Clojure, just something inspired by it.

jaen22:11:32

And core.async depends on implementation details of Clojure, using it's analyzer and whatnot

jaen22:11:38

You'd have to reimplement it for wisp

chrislloyd22:11:42

ahh, that’s why simple_smile ok

chrislloyd22:11:26

curious, why do you see clojure lib + compiler + lein being the best parts of clojurescript?

jaen22:11:36

Maybe I phrased it wrong, what I've meant is you can't really part with it simply. You'd probably have to rewrite everything from scratch.

jaen22:11:05

And I don't really like lein all that much either, I've moved over to boot and I am pretty happy with it.

chrislloyd22:11:43

ah cool, thanks for the clarification

martinklepsch22:11:25

something equivalent to the closure compiler is something that is still lacking in the JS ecosystem afaik. removal of unused code and cross module code motion being some of it’s most significant features.

jaen22:11:57

Though I'm kind of interested in why you think it's bad Clojurescript needs JVM?

kamn22:11:48

@martinklepsch: I have not really looking into it but someone pointed out this project http://rollupjs.org

chrislloyd22:11:21

@jaen: i’d love to get clojurescript to be usable in a webpack loader. i could write one that shells out to a jvm proc. but that’s going to blow out already slow build times on large apps

chrislloyd22:11:12

it doesn’t seems like there’s much to clojurescript which inherently tied to the jvm other than clojure itself

jaen22:11:13

Well, right now since you can self-host it's mostly Closure Compiler, yeah.

jaen22:11:32

So it mostly pains you due to Clojure boot-up time?

mrg22:11:51

CLJS isn't a JS library, it's an eco system by itself

mrg22:11:07

If you see it like that, these things make sense

jaen22:11:57

But if you lose Closure compiler you will end up with a couple of megs of generated code. You don't want your application to weight this much.

chrislloyd22:11:49

it’s always possible to run the closure compiler over any js code and get the same optimization, super easy with webpack.

jaen22:11:21

But then again you'd have disparate module types to deal with.

chrislloyd22:11:38

(again, don’t know the details, just curious) i think @mrg has summed up how i think of clojurescript (as a lang) vs. the rest of the community well.

dnolen22:11:39

@chrislloyd: ClojureScript doesn’t actually have any problems being adopted at big companies

dnolen22:11:55

modern JS tooling / development isn’t any simpler than the typical Clojure tooling

jaen22:11:08

Our of curiosity: what does webpack give you exactly you want to keep it so much?

dnolen22:11:18

so I don’t see how you can draw these conclusions about ClojureScript tooling

lvh22:11:20

so much more complex IMHO

lvh22:11:38

I have some macros to get access to Clojure-land stuff (specifically io/resource & slurp). I’m getting nil back from io/resource, so I’m trying to debug stuff the classpath on the Clojure side by printing stuff to stdout (with timbre, like so: (spy name) et cetera). I’m seeing the following error when building Clojurescript:

SEVERE: /Users/lvh/Projects/rackspace/crunch/target/base+system+user+dev-common+dev-overrides/cljsbuild-compiler-2/crunch/ctk_test.js:12: ERROR - Parse error. Semi-colon expected
15-Nov-18 16:41:02 zygalski.local DEBUG [crunch.test-macros] - name => core-samples/sample1.html
          ^
Am I reading that correctly? It looks like stdout from the Java/Clojure side is what gets piped to the JS output?

noonian22:11:18

I love ClojureScript tooling. Avoiding the npm toolchain and just using lein for everything makes things a lot simpler to manage for me. And figwheel is just amazing.

jaen22:11:35

Clojurescript compiler just printlns and rebinds *out*.

lvh22:11:48

jaen: Cool, thanks! So I’m not going crazy...

jaen22:11:04

I've had that exact thing once, doing println to debug a macro

jaen22:11:53

There was some function to output text to the console, but I don't remember it offhand

noonian22:11:09

(enable-console-print!)

jaen22:11:18

No, that's not it

jaen22:11:22

I'm talking about compile-time

lvh22:11:28

Alas, no closer to debugging my problem though. Correct dirs are on the classpath, io/resource still returning nil. Does the clojurescript compiler do anything funny to the classloader?

chrislloyd22:11:42

i love the clojurescript tooling too, figwheel+devcards is awesome simple_smile just trying to think about how i can introduce om-next at my org without having to ask 100+ programmers to totally re-tool

dnolen22:11:16

@chrislloyd: going back to your original question, no there’s no interest at all in removing anything related to JVM beyond what we already did for bootstrapped

dnolen22:11:44

and bootstrapped just doesn’t solve the minification issues - there’s nothing in the JS world that can make ClojureScript generated code palatably small

dnolen22:11:02

everything I’ve tried results in 2X larger artifact

chrislloyd22:11:30

oh intersting! thanks, appreciate the official stance

jaen22:11:51

I don't think you can avoid the retooling as things are. Though you might try to introduce them to boot instead of lein. It's considerably simpler to use.

lvh22:11:19

Here’s what I’m trying to accomplish. I’m writing a userscript (as in Greasemonkey) with Clojurescript. That wants a very specific kind of metadata header to be present in the output JS to work. I’m trying to test that by reading: 1. my userscript.js resource, which is just the header 2. a production built file however, whenever I do (slurp (io/resource ...)) from the macro, I get an exception, because io/resource is returning nil, which seems to mean that said file is not on the classpath

dnolen22:11:32

what I found interesting at the Conj this year was how many people told me “I started using Clojure because I tried ClojureScript and thought it was awesome"

lvh22:11:12

dnolen: +1; I’m currently helping a former JavaScript person learn ClojureScript and overall the experience has been pretty great

lvh22:11:23

(their words not mine; not that I disagree :))

lvh22:11:10

Maybe I should just rewrite this test in plain old Clojure; but I don’t think I can avoid this for all cases, because e.g. I have some tests that rely on running in CLJS because they use the browser dom; I’m using the resource mechanism to store the HTML those tests start from

chrislloyd22:11:35

@dnolen: n wasn’t aware of cljs-bootstrap — awesome work, basically what I was looking for simple_smile

dnolen22:11:09

@chrislloyd: that’s just an example. but yes via cljs.js ClojureScript can compile itself

dnolen22:11:20

this is how Planck, http://clojurescript.net, etc. work

lvh22:11:43

nice; thanks!

lvh22:11:47

that gives me a nice hint as well

lvh22:11:58

fwiw this works fine for my current debugging purposes; I’m seeing the message

lvh22:11:07

I don’t really care that the output is broken; it doesn’t work anyway 😛

noonian22:11:06

It sounds like either the folder isn’t on the classpath or you are referencing the resource by the wrong path.

lvh23:11:36

noonian: That’s what I’m assuming, but I’ve been unable to replicate on the repl

lvh23:11:55

on the plus side, jaen’s excellent suggestion was actually necessary for me to see the issue properly, and it is definitely only happening with one file

lvh23:11:05

if this ends up being me misspelling a path I am going to have some mixed feelings

lvh23:11:14

strong mixed feelings and possibly a strong mixed drink

noonian23:11:22

that happened to me the other day heh

jaen23:11:36

Hah, I'm not sure how what I said exactly helped you, but if it did then I'm glad.

jaen23:11:43

Huh, misspelling? : D

lvh23:11:45

jaen: it most definitely did.

lvh23:11:06

jaen: not quite. See, I’m capturing a compilation artifact, right?

lvh23:11:16

So I’m doing lein clean, because otherwise cljsbuild doesn’t always know to try again

lvh23:11:25

guess what gets rid of that compilation artifact...

ssutch23:11:29

hey all - im trying to figure out how to make a production build of a cljs project: https://github.com/samuraisam/om-next-starter

bbrinck23:11:42

I'm having trouble adding a defmethod for cljs.test/assert-expr. Has anyone successfully done this? I can see the multimethod is defined here (https://github.com/clojure/clojurescript/blob/c72e9c52156b3b348aa66857830c2ed1f0179e8c/src/main/cljs/cljs/test.clj#L65-L70)

ssutch23:11:55

i’ve edited the project.clj file such that lein cljsbuild once min should create a singular main.js file - but it doesn’t

ssutch23:11:20

-well it does, however it doesn’t contain anything besides a bunch of goog.require…

bbrinck23:11:35

but I can't seem to use it, even if I require that ns and use :refer-macros

bbrinck23:11:15

I found some info here about using multimethods defined in clj files here https://groups.google.com/forum/#!searchin/clojurescript/assert-expr/clojurescript/uFnrOlHKpTc/K0vw7qZFuOUJ but it did not seem to work for me

noonian23:11:24

@bbrinck: I think you need to make a .clj file my_asserts.clj and implement the defmethod there. Then in my_test.cljs have (ns my-test (:require-macros [my-asserts])).

bbrinck23:11:51

@noonian: Oh, I see what you mean. Let me try that.

johanatan23:11:36

Is it still the case that :closure-defines requires an :optimization setting greater than :none? (as stated in this thread by @dnolen : https://groups.google.com/forum/#!topic/clojurescript/7wAO_GzsITM )

bbrinck23:11:01

@noonian: Thanks a bunch for the idea! I'm having some other issues getting my clj file to show up, but I think this is promising.

noonian23:11:28

@bbrinck: np, good luck!

johanatan23:11:17

This seems to say imply that defines will work with :none optimizations (final 2 paragraphs): http://www.martinklepsch.org/posts/parameterizing-clojurescript-builds.html

johanatan23:11:29

Ok, great! Thx! Wonder why @dnolen said otherwise?

martinklepsch23:11:36

@johanatan: that’s the point of the goog-define macro really

martinklepsch23:11:50

@johanatan: I guess he just stated this before goog-define became a thing

johanatan23:11:41

Hmm, I guess I'm still confused. Why would i need goog-define and :closure-defines ?

martinklepsch23:11:17

@johanatan: have you read the post?

johanatan23:11:53

Yes, but generally I like my #defines to be specified in a compiler setting file (a la project.clj) rather than in the src code itself

martinklepsch23:11:54

@johanatan: goog-define defines a thing (with a default) that can be overridden by passing a different value to :closure-defines

ssutch23:11:56

dang! 390kb main.js with om-next, react, transit and practically nothing else

martinklepsch23:11:58

that’s kind of the gist of it simple_smile

johanatan23:11:19

So, you can't just use :closure-defines without a corresponding goog-define somewhere?

martinklepsch23:11:56

@johanatan: you can but then you need to manually add the jsdoc @define comment + it will only work with :advanced

ssutch23:11:57

martinklepsch: yes

ssutch23:11:21

however - my target is a mobile platform, and concerned about bootstrap speed

johanatan23:11:57

@martinklepsch: interesting. This seems a bit of a kludge to me-- it's good that it can be made to work but still not ideal (i.e., not DRY).

martinklepsch23:11:04

@ssutch: does that mean you’d like to not gzip things?

ssutch23:11:59

eh - it’s just that 390kb before all application code and other libraries is a lot for a little mobile processor to parse and execute before the app can run

martinklepsch23:11:02

@johanatan: what’s not DRY about it? are you suggesting not to have a goog-define statement at all and just use the compiler option?

johanatan23:11:10

Yes precisely

martinklepsch23:11:54

@johanatan: goog-define is useful for providing a default value and declaring a thing in code. Google Closure defines work exactly the same way

martinklepsch23:11:29

maybe it’s not perfectly DRY but I it seems like a good pro-documentation tradeoff

johanatan23:11:43

But you don't need a default if the values are provided in build sections-- each build corresponds to exactly one value of the define.

martinklepsch23:11:15

but then you always need to provide all defines

johanatan23:11:22

I suppose the default would be nice if you forgot to place the value in one of your build sections (but that should be avoided IMO)

martinklepsch23:11:36

plus it would be hard to “discover” defines that can be overridden

johanatan23:11:06

Well, in my case there will only ever be one define: BUILD- it will have a value DEBUG, RELEASE etc. All other divergence will hinge on the value of that one define.

martinklepsch23:11:15

there are multiple defines just in the closure standard lib

johanatan23:11:53

Sure, but I don't have to look at them. simple_smile At least until I do for whatever random incidental reason happens to pop up

martinklepsch23:11:10

but you’d have to look at them if they would not have a default 😉

johanatan23:11:25

I don't necessarily care how Google's code provides values to me- they can be hardcoded, have cascading defaults, anything really. As long as the value is there when I need to read it. However, with goog-define now I'm forced to specify a default when I know that all cases will specify their own value.

martinklepsch23:11:37

@ssutch: out of curiosity: do you have any other comparison points?

martinklepsch23:11:20

@johanatan: closure defines need defaults to be able to be used from code that does not care about those defines. I.e. you don’t want to set all the 500 closure-defines in openlayers (a closure mapping lib). In an application context this might be different but I guess this is the reason.

martinklepsch23:11:05

You can also set something to nil and explicitly override it in every build.

johanatan23:11:59

Yea, that's probably what I'll do. Thx! Is there any other way to know which cljsbuild build one's code is currently running under? Maybe I don't need a define for this at all?