Fork me on GitHub
#clojurescript
<
2016-08-08
>
isekream00:08:26

I'm new to clojure/ clojurescript and I'm building a web application . How do you compie the clojurescript files into a single js file with the relevant dependencies in production mode?

maxov01:08:58

@isekream: Turn the optimization mode to :advanced, see https://github.com/clojure/clojurescript/wiki/Compiler-Options#optimizations. I’d recommend using lein-cljsbuild, which is a very useful plugin to get started, it makes doing stuff like this much easier

isekream01:08:02

I am and I did

isekream01:08:47

question if I used a framework e.g. React or Luminus does the framework get bundled into the JS file or do I still need to package the "output" directory with it?

levitanong02:08:36

@maxov: I'd recommend you to just use JavaScript interop for either d3 or any other d3-based JavaScript library.

maxov02:08:36

@levitanong: That’s what I’m doing currently, was wondering if there was any better way. Thanks

levitanong03:08:42

@maxov: I know how you feel. I've been looking as well, but I'm guessing nobody wants to do it anymore because d3's mutations and the way it does things is so... Un-functional.

maxov03:08:52

it seems like everybody is moving to use react, but I still really like d3’s declarative style… the enter/exit selections feel pretty nice, even if they are mutable

iku00088807:08:36

@delaguardo: Thanks for the suggestion (and sorry for coming back late). I tried all sorts of imaginable variations of what could be the correct keyword for catching the compositioned event, but still not having any luck. Do you know any snippets that listen to the compositioned event in the wild?

kauko09:08:35

@maxov: are you using d3 to write to canvas? Since that is a problem that React doesn't really answer

kauko09:08:27

If you're just using d3 to manipulate the DOM and don't like React, then maybe look at Hoplon. If you're not working on an SPA, Dommy is an option.

maxov09:08:49

@kauko d3 doesn’t write to canvas afaik. I’m using it for an interactive visualization

kauko09:08:32

Well, you can use it on the canvas 🙂

kauko09:08:42

not saying that's better than the dom

maxov09:08:02

i suppose, but then data binding doesn’t work, which is a pretty big feature

kauko09:08:26

Anyway, don't feel like you need to give up d3 for react. What you're doing is exactly the thing that d3 was designed for, and what react wasn't designed for

kauko09:08:27

It's a pretty common question actually. I mean, how to use d3 and cljs 🙂

maxov09:08:08

d3 is pretty functional already, to be honest. I would love to see a clojurescript visualization library in the spirit of d3, or perhaps make one if I have the time

maxov09:08:26

the only thing that came close was c2, but the developer deprecated it, suggesting react instead

bbss10:08:11

@maxov: you might want to look at d3 v4 (which is now master) it does write to canvas.

bbss10:08:52

I think also some of the "databinding" works for canvas, or at least it has some effort to make it closer to svg wrt event handling.

novakboskov12:08:05

I came up with an idea and want to check it with you. Some of my frequently dereferenced RAtoms in Reagent should always return a specific value if they are currently filled with an empty string. I want to define a new type which is extension of RAtom and does all the functionalities same way as it except -deref from IDeref protocol which should return specific value (if (empty? @this) ...). It looks to me like a standard problem which I would solve in OOP using class inheritance - I would make a new class by extending RAtom and just override -deref. Does it even make sense in CLJS and if it does how could be achieved?

anmonteiro13:08:28

@novakboskov: seems to me you can implement that in user land by defining a new protocol and extending the RAtom type to that protocol

anmonteiro13:08:46

(defprotocol UserDeref (user-deref [this]))

(extend-protocol UserDeref
  RAtom
  (user-deref [this]
    (if (empty? @this) …))
  default
  (user-deref [this]
    (-deref this)))

anmonteiro13:08:26

but then you’d need to use the user-deref function everywhere, not sure if that’s desirable for you

novakboskov13:08:18

@anmonteiro: Not all the RAtoms should behave like this but only few of them, that's why I need a type for it, to make only that few RAtoms of that type while rest remain the same. Also, why you use user-deref instead of -deref? It seems to me that function overload by name works well:

(defprotocol IOld
  (foo [this])
  (bar [this]))

(deftype MyType [prop]
  IOld
  (foo [this] "Hello old.")
  (bar [this] (.-prop this)))

(defprotocol IProt
  (foo [tihis]))

(extend-protocol IProt
  MyType
  (foo [this] "Hello new!"))

(let [a (->MyType "type")]
    [(foo a) (bar a)])
;; => ["Hello new!" "type"]

anmonteiro13:08:35

@novakboskov: just used a different function name as an example, to be easily distinguished

cursork13:08:14

@novakboskov: Use a Reagent reaction?

(def x (r/atom 123))
(def y (reagent.ratom/reaction (or @x "foobar")))

novakboskov13:08:40

@anmonteiro: Right. Actually, I know how to extend types through protocols but what I need is to make new type based on existed one - literally parent-child relationship from OOP.

novakboskov13:08:27

@cursork: I can't find that reagent.ratom/reaction function in Reagent 0.6.0-rc...

asolovyov14:08:19

is it possible in macro to understand if the optimization mode is :advanced or :none?

anmonteiro15:08:26

@asolovyov: (:optimizations (cljs.analyzer.api/get-options))

anmonteiro15:08:40

@asolovyov: needless to say it needs to be called from Clojure

asolovyov15:08:42

of course 🙂

thheller15:08:42

@asolovyov: curious why would you want that? seems like you are asking for trouble

asolovyov15:08:51

heh, not sure I want that

asolovyov15:08:17

@thheller: I'm trying to setup cljs modules 🙂

asolovyov15:08:00

and one of the problems for me right now is that I'm not sure how do you make it so... that modules are separate and loaded separately in production, but loaded all at once in development

thheller15:08:26

why would you need to load it all at once in development?

asolovyov15:08:30

what I'm doing right now is that I have two lists of modules - which I need to load in production and in development - and switch between them

asolovyov15:08:44

and loading in development is (goog/require ns-name)

asolovyov15:08:55

which is something advanced compilation bans!

asolovyov15:08:07

I guess I'm doing something wrong

thheller15:08:09

arghhh 😞

thheller15:08:32

use shadow-build \shameless plug\

asolovyov15:08:40

hehehe I thought so!

asolovyov15:08:59

well, I'm not doing anything fancy about cljs right now so I guess I could!

asolovyov15:08:10

@thheller: the only thing... how will it help me? :-)))

thheller15:08:10

it's a shortcoming of CLJS that :modules are sort of second class citizen

thheller15:08:47

well a) you'll have the exact same config for :advanced and :none

thheller15:08:57

b) no goog.require ever

asolovyov15:08:07

a) sounds great!

asolovyov15:08:30

b) All of it will have to go though ModuleManager stuff?

asolovyov15:08:56

I'm not doing ModuleManager yet, just appending scripts right now :-))

thheller15:08:25

hmm don't have good experience with ModuleManager, usually made things slower

asolovyov15:08:34

ah good, so how do you load modules?

asolovyov15:08:40

just by appending scripts?

asolovyov15:08:58

I've looked at shadow-build-example few days ago and didn't notice anything about it there

thheller15:08:28

well ModuleManager is for loading scripts while the app is running

thheller15:08:44

i know which modules to load based on which page the user is on

thheller15:08:05

so I just emit the script tags for the module in the html for each page

thheller15:08:38

if you want to load them on demand you have to tailor it for your app

thheller15:08:10

the solution will be too specific to have a general purpose approach

asolovyov15:08:43

I guess I'll have to check results of shadow-build to understand more 🙂

asolovyov15:08:03

@thheller: thanks, I'll give it a try tomorrow 🙂

thheller15:08:02

happy to help if you have questions, :modules are an awesome tool

asolovyov15:08:09

yeah, I really hope to make my index page way smaller :-))

asolovyov15:08:30

at 1.1 mb it's not exactly most lightweight ever

cap10morgan21:08:00

(new to boot) I’ve just packaged up a JS lib for cljsjs and issued a PR. What do I need to do to deploy this to clojars under my own org name to use in the meantime?

cap10morgan21:08:06

looks like the key was getting it to read my leiningen gpg creds file by putting this into ~/.boot/profile.boot: https://github.com/boot-clj/boot/wiki/Repository-Credentials-and-Deploying#lein-credentials-file

cap10morgan21:08:38

and then running boot package push --repo clojars