Fork me on GitHub
#clojurescript
<
2017-09-11
>
athomasoriginal00:09:00

In CLJS, what is the best way to make AJAX calls? I see there is this library https://github.com/r0man/cljs-http but could one just as easily use js/fetch and if so, is there a pro to using a library?

souenzzo03:09:18

There is some way to run closure-compiler "simple" > prepack > closure-compier "adv" with cljs-build?

dimovich06:09:24

@tkjone cljs-ajax is good

dimovich06:09:15

also re-frame-http-fx if you're using re-frame

dimovich06:09:16

I'm having an issue with using npm modules

dimovich06:09:36

getting the WARNING: JSC_JS_MODULE_LOAD_WARNING. Failed to load module "react"...

cjhowe08:09:10

is it possible clojure 1.9.0-alpha20 breaks a lot of cljs tooling? i've had a lot of trouble using it with cljs on both figwheel (lein) and boot-cljs. i think part of it has to do with handling of NaN in cljs; i'm seeing things like ##NaN in the cljs.test build output. works fine on alpha19

danielstockton08:09:43

"Invalid format: 1504569600000 is malformed at ("0" "0" "0" "0" "0")" Anyone come across similar errors in advanced compilation? Everything works fine with no optimizations and I can't work out where the problem is.

danielstockton08:09:12

I'm working with dates, the number is a js/Date .UTC

danielstockton10:09:37

The error was coming from somewhere in cljs-time and I fixed it.

karlstefan09:09:45

Comming to clojure(script) from a react/js/node background I'm a bit confused as to what libraries I should try first. Any suggestions?

danielstockton10:09:34

@karlstefan What do you want to do? A good thing about Clojurescript is that you have easy access to Google Closure. This and the language itself cover a lot that you might usually need libraries for.

hmaurer10:09:06

Is google closure still, to this date, superior to the latest solutions available with webpack and co @danielstockton

danielstockton10:09:34

@hmaurer I'm pretty sure webpack is still behind in terms of dead code elimination and code splitting, mainly because closure is written in such an explicit/verbose style.

mbertheau14:09:48

(->> [] (apply max)) is nil. (->> [] (apply max) inc) is NaN. But (inc nil) isn't NaN, it's 1. What am I missing here?

the-kenny14:09:28

that looks strange indeed.

Zor14:09:46

in javascript, 1 + NaN == NaN. However, 1 + null == 1

Zor14:09:11

(->> [] (apply max) inc) => NaN smells

lxsameer14:09:55

IMO it should return nil or throw an error

Zor15:09:24

if null + 1 == 1 in JS, I'd argue Clojurescript should forward the madness from JS

akiel15:09:46

Hi. At advanced compilation, I try to leave out foreign libs like React and load them separate. I like to do it because we have many apps using the same React version (and other foreign libs). Is it even a good idea not to have one big JS file these days?

akiel15:09:18

@lxsameer I know this. My understanding is that you split your code by functionality used at different sites. But foreign libs would go to cljs-base. Than I have a different cljs-base per app, because I use different stuff from cljs itself. I like to separate stuff like React because it won’t be touched by advanced compilation.

thheller15:09:56

@akiel you can put foreign libs into their own modules by their provided namespace

thheller15:09:23

ie. create a :module for :react via :entries [cljsjs.react]

thheller15:09:20

or leave them out entirely and just use the externs and use react from a CDN or so

akiel15:09:33

@thheller Ok leaving them out and only use the externs would mean, that I build my own version of the cljsjs react lib - right?

akiel15:09:10

But I could also try to define a react module. Thanks!

thheller15:09:04

yeah it requires a bit of minor tweaking since things like reagent expect to find cljsjs.react (in non-beta versions)

thheller15:09:35

the common approach is to a create an empty namespace for everything that would otherwise be provided by the foreign libs

madstap16:09:54

@mbertheau My understanding is that js awesomely has two kinds of null and cljs treats them both as nil, except when it doesn't and the js madness leaks through

anmonteiro17:09:49

correction to the above:

(inc js/undefined)
NaN

anmonteiro17:09:03

^ there’s your issue

levitanong17:09:37

And just to add to the madness: (number? NaN) ;; true

souenzzo17:09:13

from node

~ node --version
v8.4.0
~ node
> typeof NaN
'number'
clojure is hosted. Will/should not introduce a new number logic.

chris17:09:41

❤️ js

dnolen18:09:44

@mbertheau the JIRA issue you opened is not a bug, in general it’s best to ask here and wait for someone who contributes to ClojureScript to respond before opening an issue

dnolen18:09:55

(apply max []) in Clojure throws

dnolen18:09:33

so the ClojureScript behavior has nothing to do with max, but arity checking

dnolen18:09:07

and we do not currently check primitive arithmetic ops like (inc ...) for perf reasons

mbertheau18:09:49

@dnolen Ok, but I still don't understand what's going on. A call to max isn't arity-checked, so it's value is what? And second, why does it matter how inc got its argument value (if (apply max []) does evaluate to nil)?

dnolen18:09:21

if something throws in Clojure and it doesn’t throw in ClojureScript it’s safe to assumed it’s behavior is undefined in ClojureScript

dnolen18:09:24

the exact same thing is true for passing non-numbers to arithmetic operators

dnolen18:09:30

that throws in Clojure

dnolen18:09:07

there’s nothing to understand here btw

dnolen18:09:22

we don’t check these annoying undefined cases for perf reasons, that’s it

mbertheau19:09:46

@dnolen Is it wrong to say that (apply max []) is JS undefined, and nil is JS null, and JS undefined + 1 is NaN, whereas JS null + 1 is 1?

dnolen19:09:25

yes to say (apply max []) returns JS undefined is not correct

dnolen19:09:39

that whole operation is undefined period

dnolen19:09:08

it could throw if we come with a reasonable way to do that, so you cannot depend on the result

mbertheau19:09:28

It is undefined currently, isn't it

dnolen19:09:36

to believe that (inc nil) returns anything at all is similarly unwise

dnolen19:09:48

@mbertheau it doesn’t matter what it currently is

dnolen19:09:02

you cannot depend on the behavior anyway

mbertheau19:09:41

It does matter in practice to me because knowing which things have "undefined behaviour" without compiler support is quite hard

dnolen19:09:14

of course that’s implied - and you have to live with that

dnolen19:09:26

or contribute a brilliant to solution to this multi-year conundrum 🙂

mbertheau19:09:29

After all, in practice, ClojureScript behaviour has to be explained to the developer who uses it in terms of the various JS VMs execution environments

dnolen19:09:51

JS specification - nothing to do with VMs

dnolen19:09:29

and in this case, it’s not defined at all as I already stated

mbertheau19:09:53

Hmm, I don't know how relevant the JS spec is in practice. What matters to the developer right now is what browsers actually do.

dnolen19:09:08

it’s completely relevant

dnolen19:09:19

we generate EcmaScript 262

dnolen19:09:40

we don’t generate JS for browsers

dnolen19:09:33

anyways, we could probably solve the arithmetic issues but it would be fairly dramatic change with wide ranging repercussion

dnolen19:09:45

which aren’t obvious if you haven’t been following ClojureScript dev for the last 6 years

dnolen19:09:06

so haven’t done anything about it as of yet

mbertheau19:09:36

I don't deny that, I just need to know what's going on. You have to admit that the behaviour described in the beginning is very unexpected to the unsuspecting developer.

dnolen19:09:02

sure, doesn’t mean we’re going to do anything about it without thinking it through

mbertheau19:09:38

So the take-away is, when you get nil from something, it can be JS undefined or JS null, which behave differently in different situations.

dnolen19:09:18

oh that’s a completely different thing

dnolen19:09:24

which was a bit obscured by your examples

dnolen19:09:58

we treat undefined and null as nil yes

dnolen19:09:19

since undefined doesn’t really have a useful semantic in Clojure(Script)

mbertheau19:09:57

What exactly does "treat" mean in that context? When are JS undefined and JS null "coerced" to nil?

dnolen19:09:37

the coercion only happens if you are testing for nil i.e. nil?

dnolen19:09:48

i.e. x != null

dnolen19:09:13

and during printing of course

mbertheau19:09:14

Which happens during printing on the REPL I assume

mbertheau19:09:33

Ok. So when you see an expression printed as nil or test if for nil, be aware that using the same expression in a different context may not be the same as using nil in that context, because the JS value can actually be undefined or null.

dnolen19:09:19

yes but when could that ever matter?

mbertheau19:09:28

@dnolen Is there a list of things the behaviour of which are undefined? Or is just the missing arity-checking?

dnolen19:09:30

except in this case of passing an invalid value to some other thing

mbertheau19:09:07

The unsuspecting developer can't tell that the nil they see in the repl is actually an invalid value.

dnolen19:09:12

@mbertheau there’s no list, there’s lot of little edge cases

dnolen19:09:20

@mbertheau you can’t pass nil to inc

dnolen19:09:34

so it doesn’t matter if it’s actually undefined or null in the slightest

mbertheau19:09:39

Sure: (inc nil). See? 🙂

dnolen19:09:03

see what? you can’t pass nil, it doesn’t matter the rep

mbertheau19:09:33

Then what do you mean "I can't"?

dnolen19:09:34

nil effectively unions null and undefined

dnolen19:09:44

if you can’t pass nil then you can’t pass those things

mbertheau19:09:12

When I do pass nil to inc, it comes out as (null + (1)) on the other end.

dnolen19:09:13

(inc nil) is meaningless (I’m repeating myself, and I need to switch gears here)

mbertheau19:09:07

Saying (inc nil) is meaningless may be the extent to that ClojureScript cares, but since that code compiles and a similar situation can easily appear in practice, its meaning in JS matters a lot to a developer in my opinion.

dnolen19:09:13

noted and I’ve said all I’m going to say about this for now 🙂

mbertheau19:09:44

Allright with me, I have my take-away. Thanks for your work with CLJS! I enjoy it very much 🙂

mordus22:09:24

Anyone have a recommendation for a clojurescript webgl/canvas library? Perhaps something that integrates with Pixie?

Zor01:09:33

http://thi.ng/ or https://github.com/thi-ng/ has everything you're looking for, and then more, and then even more / with a gitter community to boot