Fork me on GitHub
#clojurescript
<
2018-02-13
>
mfikes00:02:22

Crazy new capability is now in ClojureScript master for running stuff via a new cljs.main. As an example

echo "(defn square [x] (* x x)) (prn (square 3))" | clojure -Sdeps '{:deps {org.clojure/clojurescript {:git/url "" :sha "82998109292c5982380e945e7565d7425879e0f3"}}}' -m cljs.main -js rhino -e '(* 4 (Math/atan 1))' -
prints out
3.141592653589793
9
This example is a bit complicated, but at its core is command line processing capability built directly into ClojureScript (things like -e to eval, -m to specify a main namespace, etc., essentially the same kind of stuff you can do with the Clojure REPL and clj.)

mfikes00:02:16

Much simpler usage, using the uberjar, might look like

java -jar cljs.jar -e 3.14 -r
to evaluate a form and start a REPL or
java -jar cljs.jar foo.cljs
to run a file.

inkuzmin11:02:18

I am about to start a new application and choosing a react interface to use.

Roman Liutikov11:02:54

Reagent is the most widely used one, if that’s what you are asking for

inkuzmin11:02:02

Yes, I think so, thanks! I have experimented with Reagent a bit some time ago, just wanted to check that it’s still a good way to go.

beetleman12:02:38

If it will be bigger app you can take a look at re-frame. if You dont want use re-frame You can read doc of re-frame and take some ideas from it.

christos12:02:57

tonsky's rum is very good too. I have used both extensively, and i think rum is a little better.

beetleman15:02:33

@U56PV2X9T how do You manage state in rum? Does rum have something similar to re-frame/redux/mobx ?

christos15:02:02

actually tonsky has a very small article on that

christos15:02:07

we used extensively

christos15:02:04

you use a go-loop and dispatch actions much like reframe

christos15:02:27

I have used this model for other things too like asychronus communication through sockets with npm

christos15:02:08

There is also a liblary called citrus, but it makes my brain ache

beetleman15:02:47

yeah, i'll have busy weekend:D i must try this one!

jmckitrick14:02:49

Hi all, I’m taking a huge leap after convincing the CTO to let our team start using Clojure and Clojurescript. The first challenge will be integrating existing CSS into our new project. It’s a Re-frame app, but needs a bunch of CSS from an NPM less/sass project to render correctly. I’ve never worked with css pipelines, and I’ve just used gulp and webpack a bit. Where should I start?

manutter5114:02:07

I’m using lein sassc to compile my CSS files from Sass files, but really, anything that builds your CSS and puts it in the right place will work. There’s not really anything that’s necessarily cljs-specific about the CSS part.

jmckitrick14:02:22

That makes sense. But what about getting those files out of the current repo? Without just pulling out the generated css?

manutter5115:02:43

I’m not sure I’m understanding the question, but I have a .gitignore file that excludes the generated css from being included in the repository. I put the sass files in the repo, since they’re part of my project. If yours are generated externally, I’d just something like gulp to push them from the other project, thought that would be somewhat fragile, since you could mess it up if your directory structure changed.

manutter5115:02:22

I haven’t done much in the way of mixed cljs/npm projects, maybe someone else would have some advice more appropriate for your situation.

jmckitrick16:02:00

That’s exactly right, @manutter51 I need css from a separate npm project included into mine, without being too fragile.

manutter5116:02:21

I’ve never done that, but I did find an npm plugin for leiningen. https://github.com/RyanMcG/lein-npm. I’ve never used it, so I can’t say if it’s good or bad, but you might want to look at it.

deg17:02:29

Is there any reason that it should be a problem to have js/require in the expansion of a macro?

deg17:02:47

I'm still checking that I haven't done something else stupid, and my env is complex (react-native and figwheel and ...) but it seems that I get a strange error (the stack trace includes figwheel internals) if I do this unless I have previously called js/require on the same module from my .cljs code.

gneissguise18:02:49

Hello, I was wondering if anyone had tackled creating a virtual dom + diffing algorithm w/ data binding to components.. similar to React?

noisesmith18:02:32

@frostjust there’s quite a few libs using react, but none in cljs that replace react afaik

gneissguise18:02:15

@noisesmith Thanks, yeah I was looking for something in pure cljs.

noisesmith18:02:55

I wouldn’t expect a cljs solution to that to be very “pure” anyway - most of the code would be interop with the built in DOM apis

noisesmith18:02:00

(or so I’d assume…)

gneissguise18:02:37

Yeah, depending on how it chose to interact with the DOM..

noisesmith18:02:57

it would be a fascinating exercise, but I don’t know if there’s be a pragmatic benefit

thheller18:02:41

@frostjust I implemented a couple vdom things for testing but you really don't gain that much. the good thing about react is the ecosystem and having access to a lot of components. anything custom loses that.

gneissguise18:02:33

It would be nice to have something lightweight. Also having something like jsx in clojure would be interesting.. although I guess there's already hiccup.

noisesmith18:02:18

clojurescript’s reader isn’t meant to be that extensible, so you’d need a custom pre-processor

noisesmith18:02:40

unless you use something that is effectively hiccup, using valid data literals that is

gneissguise18:02:51

Haha pre-processor hell was one of the aspects of js I was trying to escape by coming over to clojure

justinlee18:02:28

and more importantly, hiccup is WAY better than jsx 🙂

justinlee18:02:33

hiccup, atoms, and specter are worth the price of admission to clojurescript in my opinion

gneissguise18:02:22

Yeah, I'll take it. I think I just need to get out of the js mindset. :male_zombie:

dehli21:02:10

Anyone know how to setup a test runner with async tests for cljs? The following results in an incorrect error code:

(defmethod report [:cljs.test/default :end-run-tests] [m]
  (when-not (successful? m)
    (throw :error)))
In order to get it working I need to do:
(defmethod report [:cljs.test/default :end-run-tests] [m]
  (when-not (successful? m)
    (js/setTimeout #(throw :error) 0))
Because it runs other tests or something after the test fails.

dehli21:02:22

Unless I use setTimeout the exit code of my test runner is always 0.

justinlee21:02:27

I’m not quite sure what you are trying to accomplish but have you taken a look at https://cljs.github.io/api/cljs.test/async

justinlee21:02:36

i personally haven’t set up a test runner in cljs yet but in javascript you basically have two options: call a “done” callback or use a test runner that inspects the js event loop and waits for it to drain before determining success or failure

dehli21:02:44

So I am using that and calling (done) in my async tests. It works fine when my tests pass but when a test fails it results in tests running after :end-run-tests which causes a 0 exit code.

justinlee21:02:42

so just from reading the docs, I think you’ll need to use core.async to wait for your stuff to finish before calling done

justinlee21:02:06

that’s what the docstring means I think

dehli22:02:30

Thanks! So actually I do wait until the tests finishes before I call done. Here’s an example:

(deftest handler-on-error
  (async done
    (let [handler (make-handler {:cleanup-workspace identity
                                 :upload-pdf
                                 #(js/Promise.
                                   (fn [resolve reject]
                                     (reject "custom-error")))})]
      (handler nil nil (fn [error body]
                         (is (= error "\"custom-error\""))
                         (is (= body nil))
                         (done))))))

justinlee22:02:46

so one of those is tests should be failing? i can’t quite follow the code but the first is seems correct

justinlee22:02:12

in other words, if you stick a (is (= true false)) before the final (done) will it exit successfully? because that would be surprising

dehli22:02:50

yep! the exit code is 0

dehli22:02:28

let me show the example output

justinlee22:02:37

okay that doesn’t make any sense. sorry you’re going to have to find someone who actually understands how the system works. 😞

dehli22:02:51

No worries!

nenadalm05:02:17

@U2U78HT5G I didn't look into your test as I have not much time right now, but this is how I fixed exit status for my tests using phantomjs: https://github.com/nenadalm/Warehouse/commit/b8e746845fe28831aefe6c48a9a007283250356e#diff-88ad3ddf861b2df52fa1fa085643b6f6

dehli12:02:22

Ahhh, thanks. I bet using exit instead of throw will do the trick 🙂

dehli12:02:55

I ended up changing how it works a little, but this now works:

(defmethod report 
  [:cljs.test/default :end-run-tests] [m]
  (set! (.-exitCode js/process)
        (if (successful? m) 0 1)))
Thanks for the help!