Fork me on GitHub
#clojurescript
<
2015-10-12
>
mikera01:10:35

quick question: how much enthusiasm is there for getting core.matrix support in the ClojureScript world? We have an issue with some discussion here: https://github.com/mikera/core.matrix/issues/81

danielcompton02:10:03

@mikera: you’re likely to find it a lot easier to get contributions if you allow cljc and drop 1.6

mikera02:10:28

Well - I'd certainly love to drop 1.6 but 1.7 is still pretty new and there are production deployments out there with core.matrix running on 1.6.

danielcompton02:10:43

@mikera: requiring 1.7 in new versions doesn’t make old versions stop working simple_smile

mikera02:10:20

Yeah, but sometimes they do like bugfixes and performance enhancements

mikera02:10:58

Not sure if it might be better to haver separate cljs and clj source anyway.

mikera02:10:39

All the implementations will be very different, it's mostly the core API and protocols that can obviously be shared

txus07:10:23

question: I have a hand-crafted legacy JS app (a bunch of files), with dependencies on jquery, openlayers and a couple more libraries. instead of a rewrite, we chose adding a cljs/om app alongside and mounting it on the existing dom. the problem I have is: I’d like to package the whole js as a single file, containing both the legacy app with its dependencies and the cljs/om app. Is there a way to bundle a bunch of JS files and their dependencies in a specific order inside the cljs app and be able to compile with advanced optimizations?

txus07:10:29

the problem I have is that if I bundle just the dependencies (via cljsjs for example), they get name-mangled and the legacy JS code can’t see them. So I’d say I need to bundle everything together

txus07:10:47

anyone has had a similar experience and would know what would be a good way?

martinklepsch07:10:31

txus: what gets name mangled? the js files packaged via foreign-libs are not touched by the compiler

txus07:10:29

@martinklepsch: I’m suspecting that when I include the cljsjs libs, since my cljs code doesn’t ever refer to them (even though they get require’d), the compiler treats them as dead code

txus07:10:06

because it seems to work if I include cljsjs, compile without optimizations and just <script> the legacy JS app — it sees the deps then

martinklepsch07:10:20

@txus: you can always inspect the compiled file to see if the files are included. afaik the closure compiler does not know about the js files itself it only gets the externs bit

martinklepsch08:10:02

> compile without optimizations and just <script> the legacy JS app what other approach have you tried?

thheller08:10:45

@txus: if you interface with any JS you will need to write externs for it

martinklepsch08:10:10

you could try packaging the legacy js app as a foreign lib and making it depend on jq/openlayers. then it should be inserted at the right spot. as long as you don’t call any legacy functions from cljs you won’t even need externs

thheller08:10:37

it is easy enough to get it included into a build but the :advanced compiled cljs might get renamed alot without externs

thheller08:10:44

I'd recommend two separate files, the legacy one and the cljs one

txus08:10:44

@martinklepsch: that is a good idea, I’ll try packaging it as a foreign lib. cleaner anyway

thheller08:10:07

keep all the legacy out of cljs compilation, you are just asking for trouble 😛

txus08:10:12

@thheller: actually that would be fine by me. Then I guess I’d need a separate build system for the legacy JS app, right? could I use closure compiler anyway?

txus08:10:34

or is there anything the JS cool kids are usign these days? simple_smile

thheller08:10:37

you have something for the legacy stuff already?

txus08:10:46

not really. So I can choose whatever I’d like

txus08:10:58

it is really messy — just a bunch of JS files, no optimization lol

thheller08:10:59

no idea what the JS world is doing

martinklepsch08:10:49

@txus: do you need to load the legacy code before cljs?

thheller08:10:57

who is going to be the "driver" of the stuff? the legacy stuff or the cljs?

thheller08:10:03

eg. who is getting called from html?

thheller08:10:44

closure compiler with JS not written for it is no fun at all

thheller08:10:17

you can use simple optimisations but that is just a basic minify, there are simpler tools for that

txus08:10:32

the legacy stuff, it’s all independent

martinklepsch08:10:44

@thheller: code passed in as foreign library is not processed by the compiler is it?

martinklepsch08:10:16

It’s just prepended as is similar to how preambles have been handled before just with dep-ordering etc.

thheller08:10:24

@martinklepsch: no it is not, but just the step of creating the foreign lib seems like too much work

martinklepsch08:10:42

creating a foreign lib without externs is effectively no work.

thheller08:10:44

and who knows what kind of issues it creates

thheller08:10:21

yeah but you gain nothing by including it in the cljs build process

thheller08:10:31

just making that more prone to errors

martinklepsch08:10:31

you save a build step

thheller08:10:46

you have one for the foreign lib

thheller08:10:49

one for the cljs

martinklepsch08:10:05

the alternative is to just append it to the cljs-built js file after it’s done

thheller08:10:55

I'd use 2 files, way easier to debug that way

artemyarulin10:10:55

Does anybody know is there an elvis operator in CLJS?

(aget o "firstChild" "nodeValue”)
is failing if first property is null

artemyarulin10:10:50

Found it:

(some-> o .-firstChild .-nodeValue)

txus11:10:53

@thheller: I ended up using 2 files and it’s perfect!

txus11:10:57

thank you 😄

thheller11:10:50

what did you end up using to build the "legacy" file?

martinklepsch12:10:28

@txus: any issues with the foreign-libs approach discovered or was it just faster/easier to do?

txus12:10:06

it was my first trial and it worked without much hassle so yeah, I just went with separate builds simple_smile

txus12:10:23

I used bower to fetch dependencies and gulp to build / concatenate, uglify etc

txus12:10:48

got terribly confused with all the options, frameworks and build tools in the JS ecosystem

thheller12:10:10

hehe I know the feeling 😉

txus12:10:28

now it’ll be fun and clean surgically removing legacy code and rewriting it into cljs / om

chancerussell12:10:34

Dumb question, but can someone remind me what the idiomatic way of getting a js object prop by string is? I know it’s not aget

thheller12:10:37

goog.object/get

chancerussell12:10:26

Thanks. Knew it was a closure thing

martinklepsch13:10:38

I just had fixed an error that only occurred in production and when compiling with :pseudo-names false (default)

martinklepsch13:10:09

when running locally it worked (even with :pseudo-names false + same optimization ofc.)

martinklepsch13:10:50

after setting :pseudo-names true everything worked fine

martinklepsch13:10:31

I’ve previously had strange problems that were fixed by setting :pseudo-names true — anyone else here?

dnolen13:10:03

:pseudo-names is a debugging feature, it’s not something that should be set otherwise

martinklepsch14:10:08

@dnolen: I’m well aware but my build breaks without it 😉

martinklepsch14:10:30

also a debugging feature isn’t particularly helpful if it magically corrects your build 😄

dnolen14:10:00

@martinklepsch: I’m pretty sure your issue is not related to :pseudo-names true

dnolen14:10:17

it’s very likely a symptom of a problem that exists in your build

martinklepsch14:10:53

@dnolen: I agree just confusing that it doesn’t occur in all contexts, preparing to debug more. this is gonna be fun 😄

dnolen14:10:21

my hunch, that you are not using a closure around your code

dnolen14:10:43

Closure is generating a name that clashes with some global thing

dnolen14:10:58

:pseudo-names true just prevents the clash

martinklepsch14:10:18

how would I wrap my cljs namespaces in closures? definitely sounds like a likely reason (name clash)

Pablo Fernandez15:10:36

When sharing code as cljc, do you put it in a different namespace? for example, if I want part of the namespace foo.models.user (validators for example) in cljc, should I do something such as foo.common.models.user?

martinklepsch15:10:08

@pupeno: you could put it in one namespace and just have bigger blocks for cljs/clj specific stuff at the end. That’s what I’ve seen a few times

Pablo Fernandez15:10:05

Let me see how that looks.

martinklepsch15:10:01

@dnolen: thanks a ton for helping me figure this out. What’s the reason it’s false by default? At least for advanced it seems reasonable to set it to true maybe?

martinklepsch15:10:33

“If you’re enabling :pseudo-names to debug a problem and the problem disappears it’s potentially a name clash. Take a look at :output-wrapper” — @dnolen think that’s a good addition to the pseudo names docs?

ddellacosta15:10:08

soooo, I’m struggling to figure out how to set stubs for various things with Nashorn, per http://dev.clojure.org/jira/browse/CLJS-1076 I just don’t even know where to begin. Is this JavaScript code I have to write? Is it Java? CLJS? Where does it go, etc.? anyone have any pointers?

andrewvida15:10:57

I’m having trouble getting cljs.test to work with a site using reagent. It throws an error when binding to elements. Does anyone have an example app that I could check out? I grabbed the polyfill from mozilla, but it doesn’t seem to be working correctly.

ddellacosta15:10:25

ha, andrewvida wrestling with something similar myself…will post an answer if I figure anything out

ddellacosta15:10:10

andrewvida: I do have to ask though, have you tried the style using a test runner as described here? https://nvbn.github.io/2015/06/08/cljs-test/

ddellacosta15:10:47

I’m struggling with doing this in a cider repl, but all my “Element not defined” and whatnot issues went away when I was able to load up my tests with an HTML stub

ddellacosta15:10:56

when running on the command line I mean

andrewvida15:10:15

@ddellacosta yep, pretty much just like the post mentioned (minus figwheel)

ddellacosta15:10:32

gotcha, me too. Hmm okay then, sorry I can’t help much more, sounds like we’re in the same boat

ddellacosta15:10:47

I’d guess you could fill out that file more with some HTML fixtures, but not sure that fits into how you want to test

andrewvida15:10:33

no problem. simple_smile

dnolen15:10:16

@martinklepsch: if you control all the JS on the page (only Closure compat) then you don’t need it to be true

dnolen15:10:46

also implcations for async module loading etc. etc.

dnolen15:10:52

so not going to change it now

ddellacosta16:10:44

@dnolen, RE: http://dev.clojure.org/jira/browse/CLJS-1076 -- I’ve been able to do a super naive stub of setTimeout in my Nashorn-based REPL simply by doing (set! js/setTimeout my-dumb-timeout-stub)…what would the right way to do this be such that it could be included in CLJS or otherwise made available to users as part of their REPL by default? Sorry, I’m a bit clueless as to where to even begin with this.

bensu16:10:29

@andrewvida: do you mind posting your test.js script and test.html? the test.js present in the blog post only evaluates the first argument, so the Function.prototype.bind polyfill should be included in the test.html

dnolen16:10:28

@ddellacosta: sorry I can’t offer any help on this right now

dnolen16:10:56

@ddellacosta: but look at the specific REPL sources (Rhino) in ClojureScript, they should how to stub out things

dnolen16:10:01

(Nashorn) etc.

ddellacosta16:10:18

@dnolen: understood, sure thing

ddellacosta16:10:01

actually that’s as much of a clue as I was hoping for, thanks very much

richiardiandrea18:10:38

Hello guys, can you guys have a quick look at my issue here: https://github.com/cljsjs/packages/pull/256

richiardiandrea18:10:06

I really don't know what is going on, it looks like cljsbuild is not prepending minified deps

richiardiandrea18:10:20

and I need some hint on how to debug the issue

richiardiandrea18:10:52

even just a switch to cljsbuild in order to see what it is importing and what it is not

richiardiandrea18:10:56

I see here that I need to include my deps in the html

richiardiandrea18:10:26

is it true? shouldn'it do it by itself, prepending them?

martinklepsch20:10:40

@richiardiandrea: I think that example doesn't make use of foreign libs support

richiardiandrea20:10:00

Martin I opened an issue on cljsbuild and with mies (David's altirnative), it looks like it's working

richiardiandrea20:10:41

Just build with mies not with cljsbuild

martinklepsch20:10:50

The mies issue is probably superfluous

martinklepsch20:10:13

Can you put your test project online somewhere?

richiardiandrea20:10:19

I mean, it works with mies

richiardiandrea20:10:35

Yes of course, give me some time

richiardiandrea20:10:17

And I think jqconsole package is good..it looks a building issue on cljsbuild (not sure, we'll see)

martinklepsch20:10:56

This is definitely strange and if mies works I'd assume that it's some kind of dependency issue

richiardiandrea20:10:38

Yes I think so too

richiardiandrea21:10:11

the project with the issue

martinklepsch21:10:12

@richiardiandrea: what do you run in that project? lein cljsbuild?

richiardiandrea21:10:01

@martinklepsch:

lein do clean, cljsbuild once min
for lein, and
script/release
for mies

martinklepsch21:10:36

cool. Will give it a spin. If you have a minute adding that info to the issue probably wouldn’t hurt simple_smile

richiardiandrea21:10:41

btw

lein do clean, cljsbuild once dev
works like a charm

martinklepsch21:10:03

thanks for being so persistent and getting it to work 👍

richiardiandrea23:10:23

@martinklepsch: @maria found an issue in cljsbuild, just an update simple_smile

maria23:10:57

@richiardiandrea: Sorry for not being clear enough, but it's actually not a lein-cljsbuild issue. In you case the example won't work if you use the :main option in combination with either :simple or :advanced optimization. So if you would add the :main option to your mies release script, you would get the same problem that jquery won't be included in the final build.