Fork me on GitHub
#clojurescript
<
2017-07-20
>
solve-calc.com00:07:45

if I want a function useable in both cljs and clj, do I have to put the function in a cljc file, or is there a way to have cljs files include clj files and vice-versa ?

bbrinck02:07:25

@solve-calc.com You’ll need to put it in a cljc file

oskarkv06:07:48

I'm making an Electron app. For Electron one is supposed to make two separate js files: one for the main process and one for the renderer process. But they are still one project. Can I have lein cljsbuild auto make both at the same time? And can I have figwheel autoload both?

oskarkv06:07:04

Maybe I don't need to make both with one cljsbuild or figwheel process, hm...

oskarkv06:07:29

Oh, I can with lein figwheel main renderer.

mrchance09:07:41

@oskarkv Oh nice, I used the cljs-electron template, which works around that by using lein cooper. Your way looks better 🙂

oskarkv09:07:24

mrchance I spent 2 days setting up everything without a template. Didn't wanna use templates that I didn't understand. 😛

mrchance09:07:52

I liked that one, it's very simple. But in general, I agree ^^

oskarkv09:07:22

I'm trying to use Electron with :npm-deps, but it says "JSC_JS_MODULE_LOAD_WARNING. Failed to load module "fs" at .../node_modules/electron/index.js" What am I supposed to do about that?

mrchance09:07:26

@oskarkv you can just (js/require "fs") since it's a builtin, not a node module

oskarkv09:07:02

@mrchance Hm but Electron tries to require("fs") and that gives the warning. Maybe I don't need to care about it, but I'm new to all this so don't really know what is wrong. 😛

mrchance09:07:33

ok, that's mildly weird, don't know why it would try that, and why it wouldn't succeed

mrchance09:07:31

Why do you have electron in your node modules? I don't 🙂

oskarkv09:07:34

It didn't complain when I was using (nodejs/require "electron") but now I'm trying (:require [electron :as e]) in the ns form @mrchance

oskarkv09:07:35

It seems nicer, and the closure compiler is supposed to be able to optimize better, if I understand it correctly

mrchance09:07:51

That's probably wrong? The template uses (js/require ...) too

mrchance09:07:06

Yes, in general that's how it should work, but maybe electron works a little differently... Don't know

mrchance09:07:19

@anmonteiro Is here, maybe he knows 😉

oskarkv10:07:06

How can I define compiler options that are common across builds for figwheel?

thheller11:07:39

@oskarkv in case you are interested I added a quick electron example for shadow-cljs https://github.com/thheller/shadow-cljs-examples/tree/master/electron

thheller11:07:18

the support for requiring node modules is a bit more solid there and should work for the main and renderer

thheller11:07:47

I gotta run though, will be back later if you have questions

oskarkv11:07:59

@thheller Hm, no :npm-deps?

deadghost12:07:36

so I'm trying out :npm-deps with :language-in :ecmascript5

deadghost12:07:01

and getting a lot of warnings like WARNING: JSC_BAD_JSDOC_ANNOTATION. Parse error. illegal use of unknown JSDoc tag "grep";

deadghost12:07:26

ignorable or fixable?

mfikes13:07:16

@deadghost You can suppress those by adding :closure-warnings {:non-standard-jsdoc :off} to your compiler options

chrisetheridge14:07:18

is it possible to reuse out artifacts when building cljs, so that builds can reuse artifacts where they can?

mfikes14:07:09

@biscuitpants by “building cljs,” do you mean building the ClojureScript compiler itself?

mfikes14:07:20

Normally, stuff in out is reused by the compiler for performance reasons (https://clojurescript.org/reference/compiler-options#cache-analysis)

chrisetheridge14:07:32

ah okay. so it can reused. we are trying to speed up our cljs builds, maybe you could help? we have 7 builds, and then another step at the end that does a transformation to the produced files. are multiple builds done in parallel? i.e more than 1 cljs build is built at a time (not just 1 build across multiple CPU’s)

mfikes14:07:13

@biscuitpants That would be handled by whatever build tooling you are using, if anything.

chrisetheridge14:07:33

right. so it looks like lein-cljsbuild doesn’t do that, so we’d need to implement it ourselves?

mfikes14:07:33

Off the top of my head, I’d be wary about having multiple compilers running simultaneously working with the same out directory. I don’t think the ClojureScript compiler is set up to guard against things that might go wrong in this situation.

chrisetheridge14:07:07

hmm, okay. is there anything else we can do to speed up builds? apart from changing the actual codebase?

mfikes14:07:56

Is this an issue at the end when you go to do an :advanced build? Or is it in the normal cycle you seen when doing normal development with :none?

chrisetheridge14:07:05

:advanced build

mfikes14:07:23

@biscuitpants I don’t have any experience trying to make :advanced builds run faster. I usually just grab a cup of coffee 😞

chrisetheridge14:07:40

haha, okay. well thank you! it may be an idea to look at other build tools

mfikes14:07:53

One thought @biscuitpants: Ensure you have set your JVM settings to have a reasonable (but not too much) RAM, and set it to a fixed amount. I’d experiment with that because it can make an order of 2 magnitude difference in some case.

chrisetheridge14:07:33

ours are set to “-Xmx1024m” “-Xms1024m”

mfikes14:07:37

(If you let the JVM manage its own heap size, things can get really slow for some reason. Likewise, if you specify too large a heap, things can slow down)

mfikes14:07:17

@biscuitpants Try an experiment with 8g

chrisetheridge14:07:32

ok gonna try that now

mfikes14:07:05

Also, another easy thing to do, if not done yet: Ensure you are using a recent version of ClojureScript. There were perf optimizations in the compiler added recently that can shave off 25%

chrisetheridge14:07:42

yeah we recently bumped to the latest version. try to stay on the latest version

thheller14:07:35

@oskarkv no :npm-deps, just manually install things via npm.

robert-stuttaford14:07:50

just to jump in here, @mfikes (ole @biscuitpants is a colleague) we’re building several :mains from a common codebase, which means all that stuff that happens before :advanced is repeated per :main — ie. the production of out artifacts. we’re hoping that we can somehow produce the entire out once, much like :none would, and then run the GCC phase in parallel, at 2x or 4x

robert-stuttaford14:07:05

what distinguishes our :main s from each other is manually selecting sub-components for a particular page’s use-case, to slim the JS those users would get. some of our js is half as big as some of the other js from the same process.

robert-stuttaford14:07:20

put another way, this is a poor man’s modules

thheller14:07:29

@robert-stuttaford that sounds like you really should be using :modules? 🙂

robert-stuttaford14:07:57

i really really want it to be modules, but i ended up having to manually write ns lists for each module, which got old fast

robert-stuttaford14:07:31

i will say that it’s been a good long while since i’ve tried it again

thheller14:07:32

don’t you have a app.page-a and the like namespace setup?

thheller14:07:35

ie. a namespace per page?

robert-stuttaford14:07:48

a main per page, which each use a different selection from a common set of components. all this code uses a defonce’d atom and a defonce’d async chan, to simplify state management. i suspect this is messing with the code-motion that modules uses; ie. glomming almost everything into the common module

thheller14:07:09

nah that was just the old :modules with bad behaviour

robert-stuttaford14:07:17

omg don’t get my hopes up

mfikes14:07:28

@robert-stuttaford One thing to look out for is that all of the :mains are built with the same “build-affecting” options. So, for example, if one has :static-fns and another doesn’t, this would defeat reuse of stuff in out

robert-stuttaford14:07:02

ok we’ll try it. @mfikes good to know. happy to report that they’re all identical other than the main and js file name (and source map file name)

robert-stuttaford14:07:18

btw i don’t say this often enough - cljs is moving forward at a phenomenal speed, in large part thanks to the fine folks on here. thank you, thank you …

deadghost15:07:16

to match the example would I (:require [react-simplemde-editor :as SimpleMDE])?

deadghost15:07:49

then do something like (def mde (r/adapt-react-class SimpleMDE))?

mfikes15:07:28

@deadghost Yes, that would be the first thing I would try

deadghost15:07:45

hmm well if I continue from that and call it as [mde] or [mde {}], I get Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in. Check the render method of data-page.

facundo17:07:18

Hi everyone! can anyone recommend resources for helping me decide between re-frame and om.next (other than their respective docs)?

souenzzo17:07:39

Checkout #re-frame community is a good start point to re-frame 😄

fedreg18:07:22

Hi all, fairly new to Clojure and until recently didn't realize clojurescript on node was even an option. Getting ready to build out a backend for a cljs app and am now wondering if I should try the cljs route vs clj since I'm much more familiar with Node than Java. Question is, is this approach ready for prime time? Any good examples/libraries you can point me to? No major requirements for this app; more for learning / experimenting with clj. thx!

henrik03:07:57

ClojureScript on Node seems no more or less mature than running natively using JS to me.

henrik03:07:35

Some things I’ve noticed though: 1. There’s no point in doing advanced optimization on backend stuff since none of it is being sent to a client. In fact, as it stands at the moment, you can run into some trouble when doing so. 2. I ran into problems doing server side rendering with the latest version of Reagent (0.7.0). I had to use the previous version in the end to get it to work (0.6.2).

henrik03:07:30

Re: Reagent, this pretty much sums up the problems: https://github.com/reagent-project/reagent/issues/296

chrisbroome18:07:01

I'm also interested in this

chrisbroome18:07:32

pretty much my defacto go-to app server is node

chrisbroome18:07:52

would be nice to start using clojurescript there and then transition to something like ring/netty (once I'm more familiar with it)

noisesmith18:07:06

the jvm clojure will use resources more efficiently and has a much simpler tooling setup, but cljs on the backend is definitely possible

noisesmith18:07:33

for example most of the time you still need to run jvm clojure to build your cljs (self hosted cljs is possible but not as robust or featureful)

kurt-o-sys18:07:33

@fedreg I did start out a cljs/node.js project before. I needed some java libs. Apart from that, I'd say, cljs/node.js certainly has its use cases and I'd start cljs/node.js without much doubt

fedreg18:07:04

Thanks all for the info. Looks like it's experimentation time!

kurt-o-sys18:07:30

Yeah, just do it. You'll see, it's a breeze.

facundo18:07:41

the best place to start IMO if you want to try cljs on the server

fedreg18:07:30

@facundo Thx! Yeah, I had seen that. Looks pretty straightforward

facundo18:07:46

I did a little toy project using it, in case you want to see how the code looks https://cljsbin-bkhgroqzwe.now.sh/

chrisbroome18:07:33

To be honest, I think the cljs/node.js combo could be a great way to get more people using clojure/clojurescript. There are so many people that already know/use javascript/node.js and being able to easily transition from that ecosystem would be a huge win. Yet another reason why https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules is a Big Deal

fedreg18:07:13

@chrisbroome Agreed. Can always switch over to JVM if more power is needed

chrisbroome18:07:45

awesome. thanks for the link @kurt-o-sys

chrisbroome18:07:00

I'm still very new to the whole clj/cljs ecosystem and community, but I have to say I'm really impressed with how helpful everyone is.

kurt-o-sys18:07:58

@chrisbroome To extend the latter: if you have any issues, just give a shout 🙂

chrisbroome18:07:36

thanks! will do

chalcidfly22:07:48

If I have a string of clojurescript, say “(+ 2 (* 5 5))“, how could I “reduce” this to “(+ 2 25)“?

chalcidfly22:07:07

In other words, is there a way I can just run one step?

chalcidfly22:07:21

Not sure if this is the right channel to ask, I just need someone with in-depth knowledge of the clojurescript compiler