Fork me on GitHub
#clojurescript
<
2016-04-20
>
fasiha02:04:29

Is it ok to have a clj/app/config.clj file and a cljs/app/config.cljs file, both of which start with (ns app.config …? Will Clojure and ClojureScript know that these are totally unrelated or will the functions in the two files live in the same namespace and cause problems?

danielcompton02:04:39

@fasiha: Ignoring macros for now, you will have no issues with having two files with the same ns, one with .clj and one with .cljs. The Clojure reader looks for it’s ‘native’ extension first (`.clj`, .cljs), then to cljc if it can’t find it.

danielcompton02:04:18

There is no way (that I know of) for Clojure or ClojureScript to have functions in both files’s loaded at the same time

fasiha02:04:59

Thanks @danielcompton! Clojure just makes life easy

lewix02:04:50

what book do you recommend for clojurescript in general

fasiha03:04:54

@lewix: I don't have a direct answer, but I'll describe what I did because I had a rough experience with googling "clojurescript tutorial". I went through @bhauman's https://github.com/bhauman/lein-figwheel/wiki/Quick-Start, then went through several React.js JavaScript tutorials and porting them to ClojureScript/sablono. Plus a lot of googling for various things as they came up… probably not the most time-efficient method 😕

lewix03:04:31

@fasiha: I'm already familiar with react/redux. I'll try fighwheel thanks

bojan.matic07:04:52

what is the recommended way of making reagent components that take optional parameters with default values? aka defaultProps in react

xcthulhu12:04:39

@bojan.matic Not that I know of; I have rolled my own thing for this.

xcthulhu12:04:57

(I try not to write too many macros but I found myself writing stuff for default arguments over and over again)

bojan.matic12:04:31

perhaps i misspoke, i didn’t mean optional as much as i meant default - so, parameters that always need to be provided but you can set a sensible default and skip it most of the time

bojan.matic12:04:47

how do you use this macro?

xcthulhu12:04:59

Well... your thing is easier

xcthulhu12:04:20

(defn foo-component [{:keys [:awesome? :style] 
                      :or {:awesome? true, :style {:overflow "scroll"}}
                      :as params}] 
; Code goes here
)

xcthulhu13:04:08

That will set awesome? to true by default, and create a default style (but you should really use CSS, this is bad practice)

xcthulhu13:04:38

My thing is basically the same instead you write defnp instead of defn, and when you are actually writing your hiccup out you can write [foo-component] and it behaves the same as [foo-component {}]

bojan.matic13:04:21

i saw {:keys} a few times in examples, but never knew how it really works…does it set missing keys to nil? I see it described as a “directive”, what’s a directive?

xcthulhu13:04:01

Yeah, it sets the missing keys to nil

xcthulhu13:04:32

A directive is a special form in a destructuring binding involving maps

xcthulhu13:04:56

The other directives are :strs and :syms but I've honestly never used those nor seen them used

alpheus14:04:37

Is there a way to force a clojurescript file to be recompiled when a macro it uses changed? The macro is in another jar.

tel15:04:58

alpheus: are you using checkouts?

alpheus15:04:21

no, I don't know what checkouts means

tel15:04:35

sorry, it’s a lein thing

alpheus15:04:40

I'm installing the jar that defines the macro in a private repo

tel15:04:49

ah, yeah

tel15:04:54

checkouts can help with that

tel15:04:14

if you put a symlink to that other project in checkouts

tel15:04:33

lein will automatically include its source paths

tel15:04:53

and you can add that path to your :source-paths in cljsbuild

tel15:04:58

(assuming those are the tools you use)

tel15:04:22

I’m doing this right now with a project I’m working on

alpheus15:04:23

Yes, using lein. Does a version ending in "-SNAPSHOT" mean the dependency always gets a fresh copy from the repo?

tel15:04:40

I believe so, yes

tel15:04:09

checkouts accelerates this even more, though, since it means you won’t even need to reload things like repls or figwheel or autobuilders

alpheus15:04:49

Checkouts means I need the source of both projects on my local machine (for the symbolic links). That may be a problem for my configuration.

tel15:04:59

yes, that is true

alpheus15:04:35

Maybe removing the corresponding .js file is enough to force a recompilation?

tel15:04:46

hm, not sure

rads15:04:46

what do you guys use to log things that happen on the client? one solution would be an HTTP endpoint that appends to a flat file. is there any reason to go more advanced than that?

rads15:04:16

now that I think about it, I might as well put the logs in a DB

lwhorton15:04:37

has anyone found a good way to get third-party library css into your clojurescript bundle?

adamfrey16:04:36

@lwhorton: by bundle do you mean some compilation target directory?

adamfrey16:04:33

because if so, I’ll use http://webjars.org + boot with something like this (sift :add-jar {'org.webjars/font-awesome #"css/.+\.css$”}) to add the file to my bundle

adamfrey16:04:24

I only know how to pull files out of jars in Boot, I can’t help you with Lein.

lwhorton23:04:54

thanks for that @adamfrey ill take a look. I’m considering a crazy pipeline of stylus -> css-modules -> css -> trimmed via csso -> clojurescript module

lwhorton23:04:01

i think the hardest part would just be something that can convert json + css into a clojurescript namespace/module exposing the proper symbols… and perhaps a runtime for loading/reloading