Fork me on GitHub
#clojurescript
<
2017-06-16
>
seako20:06:18

naomarik: i am a happy user of this plugin and it does indeed automatically reload html and css assets

udit06:06:46

What’s the cleanest way to determine if the Clojurescript has been compied for dev environment? I want to add a enable something (re-frisk) only when in dev mode. How should I go about it?

mikethompson06:06:33

@udit condition based on goog.DEBUG

mikethompson06:06:36

(def DEBUG? ^boolean goog.DEBUG)

mikethompson06:06:22

@udit I'm just trying to remind myself if you have to explicitly set goog.DEBUG or if it is set automatically. The docs not helping: https://github.com/clojure/clojurescript/wiki/Compiler-Options#closure-defines

mikethompson06:06:03

I'm sure that I remember that goog.DEBUG is automatically set to false when you use :optimization :advanced.

mikethompson06:06:52

But I'm looking at our projects and seeing that we set it to false explicitly in our prod builds. So I'm now puzzled.

udit07:06:40

There’s this discussion on google groups which sheds some light onto this, apparently the default value in all cases is true https://groups.google.com/forum/#!msg/clojurescript/7wAO_GzsITM/JicBuCjiqPAJ

mikethompson07:06:03

@udit that's me discussing it. You'd think I'd remember :-)

udit07:06:46

I should have checked the names 😅

pesterhazy07:06:59

@udit, maybe (verify and) update the wiki page?

pesterhazy07:06:37

I know I've been stumped on goog.DEBUG a few times, and superficial googling didn't help

pesterhazy07:06:23

@mikethompson in (def DEBUG? ^boolean goog.DEBUG), is the type hint necessary or a performance optimization?

mikethompson07:06:53

Necessary if you want to trigger Dead Code Elimination (from the Google Closure compiler, in advanced builds)

mikethompson07:06:35

(if DEBUG? something-which-you-want-DCE-from-advanced-builds )

darwin08:06:42

@udit I would recommend to use a macro which emits cljs code based on compiler options, this is IMO more predictable than depending on closure compiler/library features, something like this: https://github.com/binaryage/cljs-oops/blob/dcf6ef5f55ed858016fdd7554adc631dda11e614/src/lib/oops/config.clj#L21-L23

metametadata09:06:54

@darwin can macro approach be applied to cases when I want more fine-grained settings? E.g. feature flags. So that I can have several advanced build profiles producing applications with different set of features.

darwin09:06:05

@metametadata yes, you can put your own options into compiler config and it will be available

darwin09:06:31

preferrably you should use :external-config for figwheel compatibility

metametadata09:06:41

@darwin that's awesome, thank you

darwin09:06:44

@metametadata in :external-config you should put your config under your own namespaced key to prevent conflicts with libraries and other foreign code

zilti09:06:28

Is there a convenient HTTP (or, so to speak, XMLHTTPRequest) library for ClojureScript that doesn't make the impression of being abandoned?

curlyfry11:06:12

zilti: https://github.com/JulianBirch/cljs-ajax is probably the most popular one

zilti11:06:50

I already got the recommendation on the IRC channel and am looking into it, but thanks a lot! 🙂

elahti12:06:47

cljs ajax has a bit misleading name since it also ships a clj implementation

linicks13:06:42

@naomarik Looks like what I'm trying to accomplish; I'll give it a shot... Thx!

curlyfry15:06:40

A team at my company is choosing between ClojureScript (probably with Reagent and re-frame) and Elm for their frontend. Anyone here who has tried both and know some pros/cons?

bbqbaron15:06:31

ooh! yes, i know and love both. i’ve done Elm at medium production scale, Clojure only as an enthusiast

bbqbaron15:06:07

i think the TLDR is that Elm is very ceremonious. our team benefits from the very easy interrogation of Elm code, but also spend a lot of time dealing with the rigor required for things that seem trivial, but are hard to explain to the compiler

bbqbaron15:06:19

i feel like its simplicity is a double-edged sword

bbqbaron15:06:36

which i’m sure is a common refrain

captainlexington15:06:48

Yeah. I tried to do my current project in Elm and abandoned it for ClojureScript.

bbqbaron15:06:32

my throughput implementing Clojure features is much higher than in Elm, but i can refactor Elm like a moron when i’m very tired, and it’s not much slower, but it’s not remotely dangerous. grain of salt, though--i wish i had more production Clojure experience.

captainlexington15:06:40

But that was because I was trying a kind of abstraction that ended up being tricky for Elm's Union Types. For a bog-standard SPA, Elm is still something I'm interested in.

bbqbaron15:06:11

i guess maybe then it matters what kind of project @curlyfry’s team is working on! what is it, if you can say?

curlyfry16:06:36

@bbqbaron @captainlexington Thanks for your input. My team actually already uses ClojureScript 🙂 The team that's choosing between cljs and Elm are building a relatively big web application but I wouldn't say there is anything especially out of the ordinary when it comes to interaction. A lot of forms and tables!

bbqbaron16:06:04

thanks for the answer. if you’re already using cljs--out of curiosity--what motivates considering Elm? i’m a fairly flexible polyglot, but teams seem to benefit from uniformity, so why not use what you have? (not challenging your question, sorry; genuinely wondering)

dnolen16:06:20

@curlyfry NextJournal transitioned from React -> Elm -> ClojureScript and talked about it here https://www.youtube.com/watch?v=Q6Q5D6mI-34&amp;t=1s

dnolen16:06:06

@curlyfry IMO, Elm is fine technology, I think the biggest value add for ClojureScript is if you’re already using Clojure

curlyfry16:06:42

@bbqbaron I actually agree with you, I think both teams would benefit from using the same language and learning from each other 🙂 The teams do work on different products though and it's up to each team to choose their stack.

captainlexington16:06:29

I wish we had the /that/ much stack latitude at my job!

bbqbaron16:06:42

i was just wistfully thinking the same thing

bbqbaron16:06:00

guess we’d better work on our OSS presences!

curlyfry16:06:04

@dnolen Awesome, thanks!

curlyfry17:06:05

How do you guys find the js interop in Elm? I haven't tried it myself, but I've heard some people say it's kind of cumbersome

dnolen17:06:08

@curlyfry that said, the NextJournal story definitely opened my eyes about the value of ClojureScript even if you’re not using Clojure

dnolen17:06:37

and the video more less back up my claim that people who think JVM stuff is more complicated than Node.js stuff are kidding themselves

captainlexington17:06:56

It's certainly cumbersome compared to ClojureScript. I never even tried. Supposedly it forces you into a very nice interface though.

dnolen17:06:03

@curlyfry FFI so definitely cumbersome

bbqbaron17:06:09

it is as with everything else, ceremonious 🙂. at a high level, i think it depends on whether you use ports as you’re supposed to, or whether you resort to embedded native side effects as an escape hatch. the former is officially recommended, the latter is often the real world response.

captainlexington17:06:14

I guess that's the Elm Way, though - cumbersome, but makes you do it nice

dnolen17:06:35

@curlyfry Elm philosophy is a bit different here they’re OK with re-inventing a bunch of stuff - ClojureScript is not OK with that

curlyfry17:06:25

I've definitely enjoyed the js interop in cljs. Being able to use existing react components (if using a react wrapper) without much fuzz is also pretty great. You get a pretty big ecosystem almost for free.

roberto17:06:35

I like both Elm and Cljs, but what frustrates me about Elm are the breaking changes the the mixed/contradicting messages from its evangelists.

dnolen17:06:00

Elm has an understandable bigger challenge - it’s a language that’s still evolving - we just have too keep pace w/ Clojure

roberto17:06:50

yeah, but the messaging is what I have issues with. Its proponents are out there evangelizing Elm giving the impression it is stable, and when a breaking change is introduced, they are like Meh, it is not 1.0 yet.

dnolen17:06:42

right messaging that is important

roberto17:06:01

and elm’s website doesn’t add a disclaimer either

unbalanced19:06:43

anybody making heavy use of datascript in their apps?

zane19:06:17

For the following externs file:

var google = {};
google.script = {};
google.script.run = {};
google.script.run.doSomething = function() {};
Should (js/google.script.run.doSomething) work? It seems like run is being munged.

dnolen20:06:48

@zane as long as the externs is actually getting applied - should work

captainlexington20:06:34

@zane If you try it the cljs-oops way, does it work?

darwin20:06:00

@captainlexington unrelated, cljs-oops will work for sure in this case

captainlexington20:06:03

If you an access it using ["keys"], then the externs would be the place to look

zane20:06:08

Huh. I wonder if I'm not applying the externs file correctly somehow.

darwin20:06:38

(cont) assuming cljs-oops usage (gcall "google.script.run.doSomething"), which will compile to goog.global["google"]["script"]["run"]["doSomething"] which will then be turned into this.google.script.run.doSomethingafter advanced optimization pass, because string names are simply not subject of name mangling and goog.global gets optimized away.

zane20:06:48

Wasn't loading the externs file properly. Once I fixed that everything worked. Thanks, @dnolen, @cap10morgan.

rauh20:06:30

FWIW, In my built environment I log the entire Compiler config map including the externs. Which could possibly avoid such bugs. Maybe this is something lein cljs build plugin could do or even cljs compiler itself.

darwin20:06:21

I tend to use lein-pprint when hunting for project.clj / config map bugs: https://github.com/technomancy/leiningen/tree/master/lein-pprint

darwin20:06:17

when extremely paranoid, I print current cljs compiler options via a macro, expanded at the point where my failing code lives

zane21:06:54

So, if something pretty-prints as:

#object[Array One Fish,Two Fish,4,Red Fish,Blue Fish,3]
how would I go about converting it to native cljs data structures? js->clj doesn't appear to change it.

zane21:06:14

I'm guessing it's not a normal JavaScript array because it doesn't print with a leading #js.

dnolen21:06:54

probably a strangely constructed array, you may need to extend js->clj via the provided protocols

zane21:06:35

IEncodeClojure? Okay.

darwin21:06:23

try this (js->clj (.slice o))

darwin21:06:40

if o is array-like, slice should convert it

darwin21:06:27

actually this should be the trick (js->clj (js/Array.prototype.slice.call o))

zane21:06:22

@darwin, thanks for that. This seems to have sorted me:

(extend-protocol IEncodeClojure
  array
  (-js->clj [x options]
    (vec (map #(js->clj % options)
              (js/Array.prototype.slice.call x)))))

zane22:06:45

Not 100% sure why that works, but it does.

dnolen23:06:22

@zane you may be getting an Array value from a different JS context

dnolen23:06:33

this is like multiple class loader issue on the JVM

dnolen23:06:38

classes/types don’t match

urbank23:06:32

Does anyone have any ideas why figwheel wouldn't connect to the browser? it does serve the content to localhost, but it doesn't get passed Prompt will show when Figwheel connects to your application