Fork me on GitHub
#clojurescript
<
2018-09-16
>
kenran_10:09:57

I've asked a similar question in #figwheel-main but now I'm trying to go about it from another angle: if I have a clj + cljs web app (I'm using figwheel-main for development) and want to deploy that to a VM, how do I do this "correctly"? Atm I'm trying to build an uberjar and it doesn't contain my js compiled code.

kenran_10:09:56

Is there another/better way? The rest is up and running, that is, if I start my app on localhost via leiningen, I can connect from the web, but I don't want to do that.

xfyre10:09:58

@johb.maier this is the approach I personally used (host system is Dropwizard based REST app)

xfyre10:09:26

works quite well for me

kenran_10:09:10

@xfyre Thanks, I'll have a look!

xfyre10:09:32

then you’ll just need to plug it in (again Dropwizard specific construct, YMMV)

bootstrap.addBundle(new AssetsBundle("/public", "/ui", "index.html"))

kenran_11:09:01

I just this moment managed to get my js code into a jar as well.

kenran_11:09:18

But it's not found on the site, sadly.

xfyre11:09:04

I personally found it very difficult to interbreed maven based application deployment with CLJS app; the approach above is far from ideal, but works flawlessly

kenran_11:09:25

@xfyre Thank you! I figured out my mistake, but I'm definitely open to trying out your way as well as I'm not content yet.

kenran_11:09:40

I forgot to add a route for my resources...

kenran_11:09:09

In dev mode, it makes no difference, but when I have a jar, it ofc does...

ant_ant_ant12:09:21

Hey! I'm trying to get clojurescript running with figwheel and vim-fireplace. Everything seems good so far, except of the println statement. I have a (enable-console-print!) call in the beginning of my script, but calling println only works in my editor connected to repl, there is no console.log in browser

ant_ant_ant12:09:50

Calling (.log js/console 1) from my editor gives me console log in my browser, but (println 1) doesn't

mfikes12:09:05

@anton173 I think this is a Figwheel-specific issue in the way its printing subsystem is arranged.

ant_ant_ant12:09:10

@mfikes any ideas on what to do next?

mfikes12:09:01

I don't know, other than to dig into the Figwheel implementation.

mfikes12:09:42

IIRC (from digging into https://github.com/bhauman/lein-figwheel/issues/575), I think Figwheel doesn't really let you set *print-fn*

ant_ant_ant12:09:30

That’s weird because I’m running the very basic example provided by Figwheel itself

mfikes12:09:16

Yeah, with the Flappy Bird Figwheel demo, you can (set! *print-fn* 3) and it will go back to the original value on its own.

ant_ant_ant12:09:59

@mfikes excuse me, I don’t clearly understand what you mean

mfikes12:09:02

Figwheel's implementation is evidently binding *print-fn* each time something is evaluated, so if you try to set it, this binding will override your setting.

mfikes12:09:47

Here's an example to consider

cljs.user=> (def ^:dynamic *foo* 1)
#'cljs.user/*foo*
cljs.user=> (binding [*foo* 4] (set! *foo* 2))
2
cljs.user=> *foo*
1

mfikes12:09:34

FWIW, if you run a browser REPL using clj -m cljs.main, initially prints will go to the REPL. But if you do (enable-console-print!) then they will start going to the console. This is because the browser REPL doesn't bind *print-fn* during evaluation like Figwheel does. Figwheel has its reasons for doing that but perhaps its implementation could be revised to allow user code to set *print-fn*.

ant_ant_ant13:09:33

Thank you so much, Mike! So the only way to print smth to the browser console is to implement my own method?

ant_ant_ant13:09:20

Hmm.. i also see there’s a Figwheel-main project

mfikes13:09:33

Yeah, it appears figwheel-main prints to both the browser console and the REPL.

awb9913:09:46

I have a very simple ring/compojure/hiccup app running that shows average Temperature per month for a given city. And now I want to show via tool tips the different years and the temperature that went into the average using clojurescript. I am searching for a tutorial that tells me how to setup figwheel so I can do Repl development on the page and also I don't have any idea how I would send the raw data to the app. I guess I could either send it inside the rendered page or I could do a second ring route that sends data In JSON format. Any hints?

awb9913:09:46

I have a very simple ring/compojure/hiccup app running that shows average Temperature per month for a given city. And now I want to show via tool tips the different years and the temperature that went into the average using clojurescript. I am searching for a tutorial that tells me how to setup figwheel so I can do Repl development on the page and also I don't have any idea how I would send the raw data to the app. I guess I could either send it inside the rendered page or I could do a second ring route that sends data In JSON format. Any hints?

bhauman15:09:21

@hoertlehner ^

bhauman15:09:48

Walks you through REPL development with ClojureScript

awb9915:09:19

Thanks Bruce! Almost all the tutorials put there talk about react/reagent/om when using figwheel. I guess with the Ring handler feature I shoudl be able to also develop old jquery style applications with figwheel? https://github.com/bhauman/lein-figwheel/blob/master/examples/using-ring-handler/project.clj

awb9915:09:49

@U250T6MFA I am trying to keep the Frontend simple for now; this is why I want to start re sering static pages with some clojurescript addons. Once my app grows I want to go with reagent. But for now the boilerplate I have with reagent is too much for me to get some prototypes started. So I am planning to do jquery style modifications at first. And then at some stage redactor those into reagent.

bhauman15:09:14

@hoertlehner yes, but you may want to turn hot reloading off

bhauman15:09:24

to avoid confusion

bhauman15:09:34

you can do straight REPL development

bhauman15:09:09

I also reccomend that you don’t use jQuery but use the built in Google Closure libs

awb9915:09:38

@U064J0EFR 1000 thanks for developing figwheel and devcards. They are both amazing pieces of software. For me it was the trigger to get started with clojure.

bhauman15:09:59

Oh wow thanks!!

bhauman15:09:17

very good to hear 🙂

awb9915:09:23

Why would I disable hot loading? Hot loading is the reason for using figwheel...

awb9915:09:46

It is amazing what an impact a single guy can make with clojure.

bhauman15:09:57

I only said that because it sounded like you wanted to do a more stateful style of development

bhauman15:09:14

interacting with the dom directly etc

awb9915:09:18

I really just want to do a sort of data expiration project.

awb9915:09:28

I also thought of using dev cards for that

awb9915:09:53

To me dev cards is similar to a python jupiter notebook.

bhauman15:09:22

yeah except you don’t have to code in a freaking browser window

awb9915:09:31

Exactly.

awb9915:09:58

You have an example where you did show some stuff for 2048 game.

awb9915:09:43

My idea was to make a few slider controls and then basically recalculate some mathematical / statistical models dynamically.

awb9915:09:28

I have done a few data exploration projects like that with jupiter...

awb9915:09:59

And it is amazing how much better one can understand a dataset when one just uses a few sliders to select different data or to fine tune certain parameters.

awb9915:09:08

And I figure that one could start this all in dev cards.. And then once it becomes more clear which parameters are essential.. And then at some point switch it to a reagent solution for production use.

awb9915:09:26

Unfortunately there are not that many data scientists for clojure yet... So this add on to dev cards does not exist yet.

awb9915:09:07

And then an approach like hoplon has is needed to push server side data more easily to the browser.

bhauman15:09:16

@hoertlehner pushing data is really not that difficult, any websocket solution will work for you

bhauman15:09:33

httpkit is particularly easy to use

bhauman15:09:18

is very easy to set up

bhauman15:09:45

no where near as difficult as one would imagine

awb9915:09:22

What I mean is that if I use compojure then I can define say 10 routes that send different kind of data back with different parameter. For Websocket I guess I have to develop a routing protocol also somehow... And then I need also an encoding (JSON / protbuf / whatever) layer. Quite some overhead to get started with a simple app for me.

idiomancy14:09:45

What's the best client routing library for clojurescript? Seems like Secretary's kind of dead, yeah?

lxsameer14:09:52

hey folks, does any one has any experience on creating a server side web application using clojurescript ? I'd like to learn about your stack and experience

xfyre16:09:55

@lxsameer you mean a regular web app with REST API and client side in CLJS?

xfyre16:09:29

we discussed one case a couple of hours ago

lxsameer17:09:36

no, I met a server side application in cljs which runs on nodejs

awb9917:09:11

I am doing "lein cljsbuild once" and am getting an error;

awb9917:09:22

is there any way how I can find out at which step it is failing?

awb9917:09:47

java.lang.Exception: Could not write JavaScript nil

awb9917:09:23

It seems that it is compiling my client-side clojurescript; I guess that it fails in trying to complile some server-side clojurescript, but I am not sure.

mfikes17:09:28

@hoertlehner You might get more insight by enabling the :verbose compiler option. https://clojurescript.org/reference/compiler-options#verbose

awb9917:09:35

@mfikes thanks. but this still does not even show me which file it wants to compile.

mfikes18:09:22

@hoertlehner Is the stack trace included with the Exception? It is thrown here https://github.com/clojure/clojurescript/blob/c2f5aba2f59cf30dbc13c968d8ee3f0e4359d38c/src/main/clojure/cljs/closure.clj#L1982 If :verbose doesn't give a clue it might be possible to try to find where the nil is being generated and to log more context at that point by making a custom build of the compiler.

awb9918:09:11

I think it somehow cannot find a dependency.

awb9918:09:17

devtools dependency.

awb9918:09:21

I guess it is related to that.

mfikes18:09:25

If you end up revising the compiler and want to build it: https://clojurescript.org/community/building

awb9918:09:13

thanks @mfikes

awb9918:09:01

I have two source paths defined. One in :cljsbuild :builds

awb9918:09:27

The other in :profiles :source-paths

awb9918:09:33

do they have to match?

awb9918:09:59

@mfikes I fixed my issue. Thanks for your help. I just had the cljs file named "clj" and this somehow I guess then tried to compile all clojujre libraries to clojurescript.

awb9918:09:02

I guess. Not sure.

mfikes18:09:09

Cool. That's interesting though, as clj files would normally be ignored by the compiler (except for the use case of requiring macros)