This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-23
Channels
- # announcements (2)
- # beginners (246)
- # boot-dev (1)
- # braveandtrue (3)
- # calva (13)
- # cider (26)
- # cljs-dev (6)
- # clojure (75)
- # clojure-finland (4)
- # clojure-germany (39)
- # clojure-italy (1)
- # clojure-mexico (1)
- # clojure-nl (14)
- # clojure-spec (61)
- # clojure-uk (104)
- # clojurescript (125)
- # cursive (20)
- # datomic (1)
- # emacs (2)
- # figwheel-main (91)
- # fulcro (29)
- # graphql (9)
- # jobs (3)
- # jobs-discuss (9)
- # juxt (13)
- # liberator (2)
- # luminus (1)
- # off-topic (15)
- # parinfer (8)
- # re-frame (70)
- # reagent (35)
- # reitit (24)
- # remote-jobs (5)
- # ring-swagger (3)
- # shadow-cljs (127)
- # spacemacs (34)
- # yada (6)
@its.ramzi You have it running locally (without building a WAR)?
(Reagent is a ClojureScript GUI library so I'm confused by your comment -- the error you are getting is from running a backend Clojure program)
@seancorfield Check out a new Reagent project by doing lein new reagent my-app. Then launch my-app by issuing lein figwheel. Go to localhost:3449. You'll see the default app, and how changing the source causes a hot deployment. But if you save this page, you get extra figwheel stuff in the HTML which isn't wanted for production.
What do you mean save? Figwheel injects stuff into the page during development but that shouldn't affect anything
I mean hitting Control S in your web browser to save a local copy of the HTML and the other files like CSS, JS, and images that make up the site.
maybe save the html once, and then edit it as needed, but saving the page shouldn't be part of your deploy process, because yeah there's likely a lot of stuff in there for figwheel that shouldn't apply to your prod code
also saving and using the page that has been rendered by reagent will break reagent in most cases - it wants an empty dom node to inject its stuff into
if you save the page it saves what reagent wants to produce itself
If I make a simple page with one input that has an on-change alert, and then I save that page, and I go to that file on my local harddrive, I get the alert. But when I drag that page along with the compiled app.js to the web folder of a Netbeans Java Web project, I cannot get the alert to trigger. Maybe some paths get broken. That's why I would like to work with someone to help me nail down the process of developing in Reagent and then moving to production.
your best bet is probably to get the "web development with clojure" book and follow that
Right, it presumes there is a div called app which it loads into, and there needs to be a way to trigger an initialization function, but I don't know how to do that.
i think all of these web development in clojure books are assuming you're building a client side app that connects to no database.
the book I just recommended has chapters covering db integration, it won't happen the way you have in mind, but it will be easier to learn what it does and adapt than it is to figure all this out from first principles
why is it so hard for me to go from a clean pull of Reagent to deploying it in prod mode?
@its.ramzi How did you create the WAR file?
I don't see how to do that directly from the basic Reagent template... it talks about creating an uberjar but not a WAR...
@seancorfield A teammate did it and I was unable to replicate the steps. It involved putting something in the project.clj file to import the uberwar plugin and make it a build type, or something
But when I tried to replicate that on my computer, I got a filenotfoundexception and was unable to make a WAR even.
@its.ramzi You can make a standalone JAR file from the base project -- lein do clean, uberjar
-- and that will create two JAR files in target
, one of which can be run directly with java -jar target/reapp.jar
(or whatever you called the project). That will start a Jetty web server on port 3000 running the app.
I'm wondering, still, is there an easy way to extract the static html and minified app.js
No, that's not how you build web apps.
$ lein new reagent reapp
$ cd reapp/
$ lein do clean, uberjar
$ java -jar target/reapp.jar
that's all I did to get the standalone app built and runningYou can't just save a generated HTML page and expect to be able to serve it up with a live backend app somehow.
Why would you want to deploy on a Servlet container, rather than the embedded Jetty server? In general, Clojure apps don't tend to be deployed as Servlets. Most people just run them with an embedded server -- Jetty or http-kit.
I didnt want the backend at that point. I just want inputs with javascript. Then I would do an Ajax call to connect to a java backend
Well, the application templates tend to be fairly opinionated about how they work/deploy...
In my head, my knowledge of webservers probably couples too many things that are actually decoupled. Like, I want to connect to java/hibernate/postgres. And I only know how to do that with JSPs and Tomcat.
So you just want a ClojureScript front end? You don't want a Clojure back end?
My customer already has an Ember app which has a postgres database. None of the developers like Ember
You can certainly do that.
The ClojureScript build tools can be configured to produce a single HTML file and the compiled-to-JS files that would need.
And you can write your ClojureScript to interact with REST back end (which is what I assume you already have?)
Ignore view source. That's not how you get the HTML/JS for the app.
if you use figwheel to serve your page, it will contain figwheel stuff
Part of the problem with starting from a template is that it includes a huge amount of machinery -- so if you want to deviate from how that is assumed to be used, you'll have to understand a lot of moving parts.
If you only want to write a Reagent-based front end for a REST app, don't start from the template.
Read about ClojureScript build tools -- they can generate the HTML etc to disk directly.
Yes, it matters a lot.
SOAP is horrible to work with 😞
No. Don't do that.
We keep telling you not to do that.
The cljs build tools can generate the files you need directly to disk. Dev/production versions are controlled from the cljs build tools.
the cljs build tool should not be generating your index.html; typically you write an index.html to host your cljs app
(but it's a trivial HTML file since everything is dynamically added to the DOM as the app starts up)
you could copy the index figwheel made for you as a start, but maintain it as its own thing
@its.ramzi If you do lein new mies miesapp
you'll get basic HTML files for dev and release. Mies has no Clojure aspect so it's a much smaller, cleaner project to start with.
(and it'll be a good place to learn about plain ol' cljs for a front end)
Well, you're not going to use a Clojure back end right? So you don't need Tomcat.
(or Jetty or whatever)
You just want a cljs front end that calls your existing back end yes?
How is your current Ember-based GUI served up? That's exactly how you'll deploy your new cljs GUI.
Is your Ember-based GUI initial HTML rendered from a .html
file or dynamically from inside the Java app?
I thought i would serve up the HTML and JS in tomcat that way I can make Ajax calls and avoid COR errors.
at least as an exercise, i need to understand how to go from a web input to getting a row in postgres
You already have a back end for dealing with the database tho'...
You said you wanted to keep that.
Ember is front end, not back end.
No one understands that. I want to remake the back end logic but keep the Java objects with the hibernate annotations
I have no idea what you mean.
Ember is a JS framework. It is purely front end.
It is communicating with your existing Java/Hibernate/Postgres back end app which does the database stuff.
Most likely ajax calls to a REST API I expect -- which is why you need to find that out.
Your new cljs front end can work just like your Ember app, making the same sort of ajax calls to the (existing) back end.
Correct
so all i am doing is replacing the shitty ember framework with the awesome clojurescript GUI
Basically, yeah.
Like I said, you'd serve up the HTML and compiled-to-JS files the exact same way that your current HTML and Ember.js files are served up.
So you'll need to talk to the team that maintains the build process that produces the the EAR file.
Since the build process would need to include your cljs-based HTML/JS files instead of the Ember ones.
You're going to need to learn a lot more about how your current build process works.
This sort of complex, ossified build process and application structure is a lot of what more Clojure/Script programmers want to avoid 🙂
I doubt anyone here can help you with anything to do with your company's build process ¯\(ツ)/¯
But, yeah, sounds like you have a goal.
How much Java etc does your existing app have?
how would i go about having a clojure back end that talks to postgres? would i use hibernate still?
Bear in mind that Clojure apps don't use Hibernate.
There are no objects in Clojure so you don't need an ORM.
omg i have no idea how this thing is so huge. we have like 1400 js components and 400 java files, but only like 30 views. which is why i want to just scratch it and rewrite it.
as I mentioned earlier, this book covers everything you would need, with reasonable choices for pretty much everything https://pragprog.com/book/dswdcloj2/web-development-with-clojure-second-edition
and this commits us to postgres, rather than being able to change a db with a configuration change in the hibernate.cfg.xml
in clojure we avoid sql types by using a lib that hands us normal data
Unless you are using Postgres-specific SQL, you can switch DBs pretty easily.
we need to have the program run off a centralized server for now, but move to the cloud in the future
it has a chapter on deployment
If you're replacing your whole front end / back end app, you'll probably also switch to a different server model 🙂
But this is a confidential government app. So we would need to use AWS government. Not Heroku.
We used to deploy web apps to large Tomcat instances. Now we deploy each small web app as a self-contained (uber) JAR that runs either Jetty or http-kit as a standalone server.
We = the company I work for.
We run on http-kit in production but we've also found Jetty to be very stable as well.
so i guess tomorrow i begin prototyping connecting clojurescript to clojure and postgres
(we can actually select the server at application start up)
Since you're a beginner -- with Clojure/Script as well as a whole bunch of web app stack concepts, it seems -- I think you'll struggle trying to replace so much existing stuff but it will be a great learning experience.
Working with Clojure is radically different to working with Java.
i think, if i had a prototype that goes from input to a db row, then i can replicate the whole software fast
I've had good luck with using the jsvc
program to run the jar as a service
East Coast?
(Since you mentioned govt app, I'd assume DC area?)
Sorry 🙂
You'll be back online before us West Coast types...
Yeah, when I'm awake 🙂
I know lots of people who hate Ember 🙂
At work, we decided to go with React.js over Angular, but we have a pure JS front end and a pure Clojure back end.
but he didnt understand how to connect Angular to the backend. and i didnt understand how to connect Clojurescript to the backend.
Nope.
We have REST APIs on the back end (Clojure), called via ajax from React.js etc on the front end. I don't know what library our front end team chose for the REST call stuff. I can ask them tomorrow.
For one of our new apps, the Clojure back end exposes a GraphQL API but I haven't looked at the code much.
how do I run a function just once. Regardless of being called by Clojure of Closure Compiler?
I have a macro that runs twice because it is called for SSR and when compiling the JS. I just want to run it once.
It is a side effecting macro too.
^ As a fellow beginner (take this with a block of salt 🙂 ) the first thing that comes to mind is to have the function put the action in a channel and make a go block pick one value from the channel and perform the actual side effect. But I'm sure there's a much better (simpler) way to do it.
@grounded_sage the simplest (non)answer would be to eliminate the side effect - I don't think that's a good practice generally
@moxaj it's image/file manipulation which is impossible to avoid haha.
yea haha. It's a funny one. I think I have an idea to cancel the second run of it by putting the results in a map and checking on the second call if it has already been done.
@UCDNJ5L3V Fulcro uses Garden for its CSS, so see https://github.com/noprompt/garden/wiki/Media-Queries
My assumptions were correct. I have a defonce collecting the directories and files recursively. Then I cross check that when running the macro to see if it needs to be generating. Adding it to the map when I generate it. This lets me generate it just once regardless if the macro is called just from clojure, just from clojurescript compilation or both.
Hello Clojurians, I’ve been playing with yada lately and decided to go “simple” route, build on my own instead of using edge. So, right now have a resource defined, route created and trying to fire-up aleph server, which I’m having tough time to achieve.
@grounded_sage why a macro instead of a top level function call?
The the macro is used in a cljc file. Called with a map of data then returns hiccup syntax that is used to generate SSR HTML and React Component. Whilst simultaneously fetching file metadata and generating new files linked to in the HTML.
i'm having some trouble using the library algo
. in my project.clj
:
:dependencies [[org.clojure/clojure "1.9.0-alpha17"]
[org.clojure/algo.generic "0.1.3"]]
; in my source code: (ns rules-engine.core
(:require
[clojure.algo.generic.functor :as gf]))
i've run and re-run lein -U run
but it keeps telling me it can't find it:
Could not locate clojure/algo/generic/functor__init.class or
clojure/algo/generic/functor.clj on classpath.
this seems like the right syntax. anyone know what i'm missing?
just a preliminary question, did you restart your repl when you added the new dependency?
i'll try that now
give that a shot. you'll need to download the dep and then make sure its on your classpath. restarting the repl will most likely do that for you 🙂
no good... i restarted the repl and re-ran lein deps
importing third party libs has always been a stumbling block for me in clojure
12:16 $ lein classpath
/home/michael/rules-engine/test:/home/michael/rules-engine/src:/home/michael/rules-engine/dev-resources:/home/michael/rules-engine/resources:/home/michael/rules-engine/target/default/classes:/home/michael/.m2/repository/tigris/tigris/0.1.1/tigris-0.1.1.jar:/home/michael/.m2/repository/org/clojure/tools.nrepl/0.2.12/tools.nrepl-0.2.12.jar:/home/michael/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-smile/2.9.0/jackson-dataformat-smile-2.9.0.jar:/home/michael/.m2/repository/org/clojure/algo.generic/0.1.3/algo.generic-0.1.3.jar:/home/michael/.m2/repository/clojure-complete/clojure-complete/0.2.4/clojure-complete-0.2.4.jar:/home/michael/.m2/repository/org/clojure/clojure/1.9.0-alpha17/clojure-1.9.0-alpha17.jar:/home/michael/.m2/repository/org/clojure/core.specs.alpha/0.1.10/core.specs.alpha-0.1.10.jar:/home/michael/.m2/repository/cheshire/cheshire/5.8.0/cheshire-5.8.0.jar:/home/michael/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.9.0/jackson-core-2.9.0.jar:/home/michael/.m2/repository/org/clojure/spec.alpha/0.1.123/spec.alpha-0.1.123.jar:/home/michael/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-cbor/2.9.0/jackson-dataformat-cbor-2.9.0.jar
oh! restarting emacs seems to have done it
so maybe that repl restart didn't take
in spacemacs- , s X
which is cider-restart
or I have also seen people have a copy of project.clj somewhere else and edit the wrong copy
I got a beginner question.... how does clojure promise differs from the java concurrent future?? Can someone tell??
java.util.concurrent.Furture is an interface with many different implementations with different behaviors
Future as an interface is largely about supply something that represents a value that may be supplied at a later date (it has some other methods like isDone, and isCancelled, that imply something about the execution model)
a clojure promise also represents a value to be supplied later, but gives both a way to represent the value to be supplied later, and a way to supply it, and a promise doesn't have methods to "cancel" it, because it doesn't assume a promise's delivery is tied to some concurrent task