Fork me on GitHub
#clojurescript
<
2017-01-03
>
qqq00:01:21

what is the correct way to include a macro in a *.cljc file? I currently have to put a #?(:cljs ...) line in the :require-macros part, and a #?(:clj ...) line in the :require part ... and maintaining both parts is error prone. Is there a easy way in cljc to say "include this amcro, do the right thing whether you're in clj or cljs" ?

mfikes01:01:44

@qqq With the recent releases of ClojureScript you can just use :require and :refer like you would in Clojure and the ClojureScript compiler will just "figure it out."

mfikes01:01:56

This is Implicit macro loading detailed here: http://clojurescript.org/about/differences#_namespaces

mfikes01:01:03

The TL;DR is that oftentimes reader conditionals in ns forms are no longer necessary.

cfleming01:01:43

I’ve added it to my project.clj and require’d it as described in the doc, but when I try to execute (let [db (js/AWS.DynamoDB.)] …) I’m getting:

~/d/cljs-aws-test> node target/main/lambda.js

/Users/colin/dev/cljs-aws-test/target/main/cljs_aws_test/main.cljs:9
  (let [db (js/AWS.DynamoDB.)]
           ^
ReferenceError: AWS is not defined
<stacktrace>

cfleming01:01:56

I’m sure I’m missing something obvious, but I have no idea what.

cfleming01:01:23

It looks like the generated JS contains: cljs.core.load_file("target/main/aws-sdk-js.inc.js");

dnolen01:01:45

@cfleming if you’re using a Node module you cannot require that in the normal way

dnolen01:01:58

(def AWS (js/require “aws-sdk”)) is what you want

dnolen01:01:31

externs should not come into play with Node.js unless you’re using advanced compilation for some reason, and I don’t see the point of that

qqq02:01:02

@mfikes: I'm reading through that; what version of cljs do I need to use that?

cfleming02:01:51

@dnolen Ah, thanks - it’s odd, I’ve seen examples using the other way, but that seems to work, thanks.

cfleming02:01:13

They may have been old or something, I’m not sure.

mfikes02:01:17

@qqq Any of these: r1.9.293 r1.9.229 r1.9.227 r1.9.226 r1.9.225 r1.9.216 r1.9.211 r1.9.198 r1.9.183

qqq02:01:05

@mfikes: I'm using 1.9.229 so I'm good; thanks for the insight! glad someone finally solved this annoyance, my :require and :require-macros section was getting unmanageable

jtmarmon03:01:24

i'm trying to figure out the repl workflow when working on an isomorphic clojure app (clojure server with clojurescript frontend, using figwheel). i want to be able to send code to my server repl from my clj code, but also to figwheel from cljs. anyone have any recommendations on this? it feels pretty janky right now (i've been booting lein figwheel and connecting to that but that seems to be the frontend repl)

tbaldridge03:01:20

Sadly that's going to be really dependent on your tooling/setup

tbaldridge03:01:10

I did it on one project via a nginx instance that proxied my CLJ server endpoints, and combined them with my figwheel endpoints into a single unified API.

tbaldridge03:01:25

But that took about 3 devs about 2 days to configure, lol

jtmarmon03:01:54

wow. yeah i mean for now i really only need the repl on the server so my temp solution is just running the server repl, connecting to that, and manually launching figwheel from the repl

jsus11:01:02

>That will only work for type 1 components. For type 2 and 3 (and also for type 1 so that reagent can cache results), put the components in vectors like (defn root [] [component]) This 🙂

ewen12:01:46

@jtmarmon if you are an emacs user, replique supports this workflow (without figwheel though) https://github.com/EwenG/replique.el

emccue13:01:42

Question: is it possible to replace the usage of the Google closure compiler with uglifyJS if I do not call any Google closure Library code. Like, If I compile with optimizations simple, could I then run everything through browserify/webpack followed by uglifyjs. The reason I am thinking of this is, the differences between and merits of Google closure and uglidyjs aside, both optimize the code to a degree. But with uglifyJS, I could require a node dependency and be reasonably certain that it would be optimized; whereas with Google closure incompatible code is abound in popular libraries. If it is possible, could figwheel still work?

dnolen14:01:04

@emccue uglify cannot do effective dead code elimination, using anything other than Google Closure will likely result in at least a 2X larger artifact

mpenet14:01:49

The only thing that comes close to Google Closure for DCO, inlining & co (in my experience) is the ocaml compiler via Bucklescript/Reason, but this is not for raw js.

emccue14:01:37

Hmm, what would results be if I ran advanced compilation with "require" defined as an extern, then ran that file through webpack/uglifyJS

dnolen14:01:01

@emccue I don’t understand what you are trying to accomplish by doing that

emccue14:01:53

Well, right now I am trying to use react-player as per the tutorial on bundling foreign libs. I have been having troubles getting leiningen to include the bundled dependencies before the generated code, so the only solution I have working is including the foreign bundle in the html before the app.js This is unsatisfactory for me, mainly because I don't know how to do tests properly: if I test my app.js and call js/something that will be nil in testing but not in the browser. Literally catting the files together works, but that is pretty inelegant. So the thought was that I could bypass the whole 2 separate bundles thing by running what cljsbuild spits out through a second watcher; but to be fair all of this is rooted in my incompetence.

dnolen14:01:54

I would rewind and try to get the foreign lib approach working

dnolen14:01:05

Leiningen doesn’t have anything to do with that

dnolen14:01:39

it’s just a ClojureScript compiler thing - you need to add a foreign lib and your own ClojureScript code must require that dep

emccue14:01:40

Yeah, I think I might be getting a silent error there. The synthetic namespace is required in my .core, so I don't think that is the issue. If I change the path to be invalid the build breaks, so it is at least seeing the bundle, but when I check window.deps nothing was defined (I posted the config I was trying a bit above, If you have any insights, or can rule that out as the source of trouble)

dnolen14:01:34

@emccue doesn’t the tutorial cover this and doesn’t it work?

dnolen14:01:47

I would get it working w/o involving whatever other variables your project may imply

emccue14:01:03

The tutorial works completely

emccue14:01:25

It just stops at putting the bundle in a separate script tag

dnolen14:01:58

oh the tutorial doesn’t describe how to avoid that?

emccue14:01:06

I haven't yet found a tutorial on foreign libs that covers this use case

dnolen14:01:02

@emccue there is no use case here. foreign libs works the same doesn’t matter what you are doing.

emccue14:01:44

I have; I'll give it a try again when I am out of work. Do foreign libs require an :externs file when you are accessing it through the global namespace?

dnolen14:01:21

@emccue currently foreign libs always need externs

emccue14:01:47

That may be my issue then; I'll try it with a blank externs file

emccue14:01:24

If that ends up being the case; perhaps the compiler should output a warning if there is a :foreign-lib without an extern provided

dnolen14:01:02

@emccue this doesn’t make as much sense as you might think since you might not use advanced compilation

emccue15:01:34

Yeah I guess that makes sense; I will report if this works at a later point

bhauman15:01:55

@jtmarmon: in figwheel you can switch the cljs repl from front end to backend when you :cljs/quit

tankthinks17:01:13

is there any documentation around providing a javascript lib from clojurescript? e.g. create a react component with reagent to be consumed by non-clojurescript app

dnolen17:01:02

@tankthinks not really because it’s not that practical

dnolen17:01:29

JS users will get a whole bunch of things they can’t use - like the standard library etc.

tankthinks18:01:05

hmmm … my “problem” is my team is using clojurescript but we don’t mandate that other teams have to use it too

dnolen18:01:18

if you want to expose something that’s not so hard

tankthinks18:01:34

we can easily consume their components but what if I want to share something with them

dnolen18:01:42

^:export works on individual fns, and it works via goog.exportSymbol

dnolen18:01:16

this prevents renaming so outside people can call into your ClojureScript even if it’s advanced compiled

tankthinks18:01:13

thanks @dnolen, I have some reading to do

tankthinks18:01:45

I’ll start with the goog.exportSymbol documentation

tankthinks18:01:38

if I ^:export a fn, am I going to export any called fns too?

emccue18:01:46

No, just the one you told it to export

tankthinks18:01:34

would you recommend going down the ^:export route for sharing react components that I know will be consumed by non-clojurescript apps, or should I simply write those in js?

emccue18:01:24

As far as I'm aware that will be fine with the caveat (at least in reagent) that you should wrap your components (which are returning persistent vectors; not exactly directly consumable) with r/as-element

emccue18:01:30

(sorry reactify-component)

emccue18:01:55

Om is likely a different story

tankthinks18:01:31

thanks again @emccue! I didn’t see that reagent doc … should have read the “news” 😃