Fork me on GitHub
#clojurescript
<
2016-09-26
>
darwin00:09:20

IMO it is great that there is a new option to run closure without JVM, but I’m not aware of any game where this could be considered a game changer 🙂 are you aware of any? e.g do you know any bootstrapped app where this would unlock some fundamental new powers with advanced optimizations on client-side?

jrheard01:09:47

is there a standard way to check for logical truthiness, aside from using an if statement?

jrheard01:09:06

i’m in a test and i just want to be able to say (is (truthy? (function-under-test)))

jrheard01:09:15

i can just define truthy? myself, just wanted to see if i’m missing something super obvious

jrheard01:09:47

nah, my function under test returns logical truthy values, like 1, etc, instead of always returning true

jrheard01:09:37

i was able to easily solve the problem by just doing (def truthy? [x] (if x true false)) and vice versa for falsy?; perhaps the fact that i had to define these myself is that an indicator that i’m doing something wrong/unusual

hjavaheri01:09:12

@jrheard you can call boolean on it

hjavaheri01:09:28

(boolean something-truthy) => true

jrheard01:09:00

nice, thanks!

hjavaheri01:09:07

(is (true? (boolean (function-under-test))))

jrheard01:09:29

i guess i’ll stick with my truthy/falsy functions for now, since (is truthy? (function-under-test)) is slightly less verbose than (is true? (boolean (function-under-test))), but in future non-test situations when i have this problem, i’ll reach for boolean

danielcompton01:09:49

@darwin you could run a dev environment entirely in the browser?

danielcompton01:09:59

could be a good getting started environment

Alex Miller (Clojure team)01:09:12

why not just (is (function-under-test)) ?

jrheard02:09:16

aha, didn’t know that would work! shoulda tried it. thanks!

jrheard02:09:37

and i’ve got (is (not (function-under-test))) for the falsy cases, neat

Alex Miller (Clojure team)02:09:19

identity is the truthy function

liamd02:09:17

i can’t get my atom to change to a new default state even though i’m using def and have restarted figwheel 11 times? any idea?

liamd02:09:33

i’m clearly missing something here

liamd02:09:16

i’m very silly and had this in my code:

(on-show [this]
      (reset! state {:text-x 20 :text-y 30}))
😳 nevermind

royalaid02:09:35

Hey all, I am trying to play around with making externs for adapter.js (https://github.com/webrtc/adapter) so I can try some things with webrtc. It seems to be much harder than I expected because adapter.js is a polyfill. Normal looking externs don't appear work. My current thinking is something along the lines of this:

navigator = {
    "getUserMedia":  function () {},
    "mediaDevices":  function () {}
}

navigator.prototype.mediaDevices = {
    "getUserMedia": function () {}
}

navigator.mediaDevices.prototype.getUserMedia = {
    "then": function () {},
    "catch": function () {}
}
to support https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia and https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getUserMedia

royalaid02:09:48

Unfortunetly this causes the closure compiler to point out that navigator is contant

royalaid02:09:54

any suggestions?

bthesorceror03:09:01

I have a question about foreign-libs if anyone has a moment

bthesorceror03:09:58

I have a dependency that is in the form of http://<remote url> but when I compile it looks in my local file system and a I get a file not found exception, I am running this on ubuntu

ag06:09:07

hey guys… anyone using doo as test runner? I can’t get it to work. just adding the plugin dependency (without any other changes) already breaks things. Starting figwheel seems fine, but then it complains about js/testable.js which I assume is part of default configuration of doo. Also when I start figwheel it throws a strange message:

----  Could not Analyze    ----

  java.lang.IllegalStateException: assert-args already refers to: #'cljs.support/assert-args in namespace: cljs.core, compiling:(cljs/core.clj:139:1)

----  Analysis Error  ----
Any clue what that may be?

jrheard06:09:05

@ag: doo’s working fine for me, here’s my setup: https://github.com/jrheard/voke/blob/master/project.clj

jrheard06:09:12

i just lein doo phantom test and it works

ag06:09:01

excluding clojurescript from lein-doo fixed the compile-time warning, but still whenever I go to localhost, it’s trying to get js/testable.js I don’t have that thing listed anywhere.

jrheard06:09:13

i’m heading to bed, but https://github.com/bensu/doo/search?utf8=%E2%9C%93&amp;q=testable.js hopefully has the answer somewhere

jrheard06:09:02

(does your build map have a :compiler map whose options specify an :output-to string? might be relevant, but i don’t know the answer any more than you do - glgl!)

ag06:09:56

I don’t get it

ag06:09:49

searching in all output .js files, they don’t contain js/testable

ag07:09:13

I add doo dependency (either plugin or lib) - the app breaks 😞

dimovich09:09:18

Hello. What is the current alternative to shoreleave? Seems it hasn't been updated in a while

hlolli09:09:30

Does someone know if the 2nd edition of Clojurescript up and running by @stuartsierra and Luke VanderHart was delayed publication, if not, where is it available (can't find it on O'Rilley online shop).

Aron11:09:11

is anyone using transit-js?

Aron11:09:24

or the transit format itself?

reefersleep11:09:53

@jrheard: Only a week or two ago, I also implemented the truthy? fn, and I had the same feeling - "why isn't this in core?" (To recap: (defn truthy? [x] (if x true false)))

reefersleep11:09:25

I mean, there is true? and false?, so leaving truthy? out seems like an oversight.

reefersleep11:09:41

It's quick enough to implement yourself, but truthyness is a basic building block of the language, so it seems like it should be in clj/cljs core.

darwin11:09:09

or maybe not 🙂

reefersleep11:09:16

I would say: not 🙂

reefersleep11:09:39

That's better!

anmonteiro11:09:01

that’s what (if x …) gets compiled to

darwin11:09:16

I think your version of truthy? is not optimal, because it will call cljs.core/truth_ instead

anmonteiro11:09:34

truthy? would imply 2 fn calls

reefersleep11:09:48

I was nowhere near optimization territory, it was more of an exploration

reefersleep11:09:10

I think that I would still prefer for the fn to be called truthy? rather than boolean, though, but that's because I'm caught up in the true? and false? naming scheme

reefersleep11:09:37

It might be that boolean slots in neatly with other naming conventions in core.

hlolli11:09:09

some? = truthy?

reefersleep11:09:59

Again, the "truthy" aspect is avoided

reefersleep11:09:24

We speak of truthyness when talking about aspects of Clojure, but avoid it in the fn names. Or, at least in this one case. 🙂

reefersleep11:09:41

But good to know, @hlolli!

reefersleep11:09:54

I just find it a bit weird, since after reading about truthyness in a Clojure guide, it would be very natural for anyone to be wanting to ask: is this value truthy?

reefersleep11:09:48

Especially since you can ask the same for false? and true?, and since using these two fns as a newbie might trip you up regarding the truthyness of your value (it did for me, anyway!)

hlolli11:09:20

Yes, sometime I manually find myself returning true and false. But by far most of the time when does all I want. Its just a question of habits probably coming from other languages like Ruby I would guess.

darwin11:09:34

I don’t get it, truthiness is implicit question, instead of (if (truthy? x) ...) you simply say (if x ...)

reefersleep11:09:43

Yes @darwin, but sometimes you might want to use it in a different way, say (map truthy? [1 nil false "five"])

reefersleep11:09:12

In which case, I guess you'd use some?. Which is fine!

darwin11:09:20

(map identity …)

reefersleep11:09:04

Avoiding truthyness again (and why? I have never heard "identity" mentioned in newbie guides, but "truthiness" loads of times)

reefersleep11:09:44

There is nothing wrong with those fns 🙂 I just find the naming, or at least the lack of explicit truthy-ness in the naming, a bit counter-intuitive

darwin11:09:20

ok, I get your point now, have nothing against another function for it, for code to read better

hlolli11:09:26

You can rename some? to be truthy? when you require cljs, but this would cause everyone looking at your code to become very confused.

reefersleep12:09:46

@hlolli: Yes, and I wouldn't want that. I would prefer Clojure itself to be that tad more newbie-friendly and have the more appropriate name in core. If indeed it is more appropriate - I can't say. I was just confused, personally.

darwin12:09:00

btw. some? is not exactly truthy?, AFAIK some? is (not (nil? …))

reefersleep12:09:21

Good to have that cleared up.

hlolli12:09:45

yes @darwin it does not handle false, I was wrong.

reefersleep12:09:05

Where does the identity name come from? I think I've picked it up in some general functional concept vocabulary.

darwin12:09:52

booleans and identity functions come from maths 🙂

reefersleep12:09:15

(I'm not going to march with banners in order to change cljs/clj core, btw, just pondering stuff out loud here : )

reefersleep12:09:36

@darwin: Cheers 🙂 Thought it might be something like that.

darwin12:09:08

btw. I have another example where I don’t write idiomatic code to be more readable, I’m using (not (empty? coll)) instead of (seq coll), it just reads better IMO

reefersleep12:09:33

I tend to agree with that, although I've been trying to alter my perception by forcing myself to use (seq coll) so that reading code with that in it doesn't cause me cognitive strain 🙂

hlolli12:09:24

After this discussion truthy? would not be really bad idea. But I think clj.core community would be those you would need to convince.

reefersleep12:09:50

@hlolli: Yeah, and I'm really not up for that. 😄

reefersleep12:09:15

In general, I'm hoping for the implementation of specs in core fns to give Clojure and ClojureScript a huge boost in newbie friendliness (and general developer friendliness!)

reefersleep12:09:37

It's far from the easiest language to get started with.

hlolli12:09:18

clojurescript is not newb friendly at all, that needs to be improved. One newb trap is not to learn clojure first, another roadblock is of course the tooling madness one needs to understand. What do you think is the most diffucult part of understanding cljs @reefersleep ?

reefersleep12:09:01

That's a tough question, @hlolli... Can't name one thing off-hand.

reefersleep12:09:46

But the confusing error messages and stack traces are definitely a candidate.

credulous13:09:51

I’m working on my first app, and using the Luminus template. For some reason my compiled app javascript has stopped loading, and I can’t figure out why.

credulous13:09:44

In the target/cljsbuild/public/js/out/myproject directory, app.js is present and is exactly what I’d expect

credulous13:09:13

I can load any of the other files in that directory, like core.js, absolutely fine

credulous13:09:49

And this just seemed to happen on it’s own (I know, obviously it didn’t, but it seems that way) — I wasn’t mucking with project.clj when it began.

credulous13:09:27

Anyone encountered a config issue like this before? I’m four hours into it and getting irritated with my own thickness

hlolli14:09:42

you are opening a .js file? load it in html with <script src="app.js"></script>?

pseud15:09:30

Am I correct in understanding that I cannot use cljs.spec’s fspec for much of anything without requiring clojure.test.check.generators too ? (Everytime I pass in a spec which, at some level, uses fspec to s/conform I get a stacktrace complaining about clojure.test.check.generators not being required

Alex Miller (Clojure team)15:09:11

When trying to check whether a function conforms, the way that's done is by invoking it with generated args

Alex Miller (Clojure team)15:09:25

Which requires the arg generators

dnolen16:09:26

@sundbp that doesn’t sound right to me

dnolen16:09:44

I’ve been using s/conform without issue wrt. to loading test.check generators

sundbp16:09:15

(bad autocomplete I believe)

Alex Miller (Clojure team)16:09:33

this is specifically for fdefs with fspec (higher-order fns)

Alex Miller (Clojure team)16:09:26

sorry, I’m thinking of instrument conformance, not just s/conform

Alex Miller (Clojure team)16:09:17

but maybe it’s the same thing

Alex Miller (Clojure team)16:09:27

something like (s/conform (s/fspec :args (s/cat :x int?)) #(println "hi" %)) will generate int args for :x and invoke the function

Alex Miller (Clojure team)16:09:39

so will fail if test.check is not available for generator support

Alex Miller (Clojure team)16:09:10

there is no other way to verify that a passed function conforms to the spec you’ve specified using fspec

pseud16:09:23

OK, so in essence if I wanted a more racket-like way to check my functions I’d have to use spec checks inside :pre & :post assertions on my functions

Alex Miller (Clojure team)16:09:38

I assume s/assert came over to cljs :)

pseud16:09:03

It’s there, I saw it earlier today, I’ll just have to enable assertions to use it, but that’s a minor problem 🙂

dnolen16:09:15

@pseud assertions are enabled by default

pseud16:09:17

Well, maybe it was my boot project then, but (s/assert) happily powered through some tests that should’ve spat out metres worth of stacktraces 🙂 I’ll just be sure to enable asserts

jrheard17:09:29

hm - so part of my cljs app uses a couple of vanilla JS files, and it gets access to them via a couple of <script> tags in my html page, like so: https://github.com/jrheard/voke/blob/master/resources/public/index.html#L10-L11 but now i’d like to test this part of my cljs app (i’m using cljs.test and doo) what’s the recommended way of giving my app access to these vanilla JS files at test time, so i can test code that makes calls like (js/Collision.foo), etc?

dnolen17:09:41

@jrheard that’s what :foreign-deps is for

jrheard18:09:52

aha - thanks!

jrheard18:09:17

it works! 😄

jrheard18:09:52

one js file depends on the other directly, so i was worried that that would be an issue, but adding both to foreign-libs and requiring both of their namespaces seems to do exactly what i want

dnolen18:09:44

@jrheard I would hope so 😉

royalaid18:09:39

Gonna repost a question I had last night for visibility: https://clojurians.slack.com/archives/clojurescript/p1474857935004614

royalaid18:09:00

Any help is much appreciated

dnolen18:09:12

@royalaid doesn’t look like valid extern format to me

dnolen18:09:18

please see the Closure documentation on this

royalaid18:09:48

I tried a few different ways

royalaid18:09:56

and I agree that it looks very wrong

royalaid18:09:00

should be something like

dnolen18:09:06

see the documentation

dnolen18:09:27

also CLJSJS libs have good examples

royalaid18:09:46

The only real sticking point is that navigator is const

royalaid18:09:15

and a global object

dnolen18:09:42

do not use strings

dnolen18:09:49

do not use bags of methods like that

royalaid18:09:16

Is what I was using as my guide

dnolen18:09:37

yet what you wrote above doesn’t appear to follow the conventions

royalaid18:09:15

Yup, kinda bashing my head against the wall trying to get to some kind of result 🙂

dnolen18:09:54

like I said you can't just write regular looking JavaScript as you’ve done

dnolen18:09:59

it’s not going to work

royalaid18:09:40

MediaDevices.prototype.getUserMedia = function(constraints) {} from the compiler externs would be analogous to

navigator.mediaDevices = {
    "getUserMedia": function () {}
}

royalaid18:09:56

I guess that is where I am getting lost

royalaid18:09:03

I don't get where MediaDevices comes from

royalaid18:09:20

because it is attached to navigator inside of the browser window

dnolen18:09:15

@royalaid I think you’re missing the important point about what I am saying

dimovich18:09:34

using cljs-http, and getting a network error. Chrome is printing this:

dnolen18:09:39

navigator.mediaDevices.getUserMedia = function () {};

dnolen18:09:53

@royalaid you need to write it like this ^

dnolen19:09:38

@dimovich you cannot make cross domain requests so you need to do something else

dimovich19:09:00

hmm... any options on the client side?

dnolen19:09:04

@dimovich this isn’t a ClojureScript question really - it’s just how browsers & JavaScript work

dimovich19:09:28

ok. thanks for the info... Back to the backend now 🙂

royalaid19:09:25

@dnolen Okay making more sense now

royalaid19:09:00

so for chained methods just keep building the chain via . notation?

dnolen19:09:55

@royalaid it’s not about chaining

dnolen19:09:04

it’s just about how you’re supposed to write externs

dnolen19:09:12

sorry I can’t say anymore about this than I already have

royalaid19:09:38

thanks for the time

pseud20:09:00

So cljs.spec/assert isn’t working out for me, REPL example: http://paste.lisp.org/display/327173 Note. I’ve also tried calling it from within functions I know are being executed (and added some print statements to verify the changes being picked up) - s/assert is ignored while regular asserts aren’t, any clues ?

pseud20:09:07

nvm - rt?m. (s/check-asserts true) worked wonders

novakboskov20:09:12

Is it posible to mark all the symbols in a namespace with ^:export (without doing it literally)?

ag21:09:40

guys, I still can’t figure out my problem with lein-doo. would you help me to figure this one out? https://github.com/bensu/doo/issues/117. Thanks a lot!

bensu21:09:23

try putting :output-to inside :output-dir

ag21:09:23

you mean like this?

:output-to     “resources/public/js/tests/out/test.js”
:output-dir    “resources/public/js/tests/out”

ag21:09:47

that didn’t help

dnolen21:09:42

@ag it’s a bit difficult to debug your problem since that repo doesn’t make any sense wrt. to the project.clj

dnolen21:09:58

you’re outputting to some directory

dnolen21:09:08

but then your report tries to load something that doesn’t match

dnolen21:09:20

you refer to a :main that doesn’t even exist in that repo

dnolen21:09:05

these should probably be sorted out first

ag21:09:03

oh right.. I took some parts from other project, but why doo even bother doing anything when I am not doing (in figwheel) anything related to test profile?

dnolen21:09:11

I don’t know what you’re talking about since I didn’t actually try that project given the above problems

ag21:09:11

yeah, it’s not very related to clojurescript (I guess) just couldn’t find better channel to ask for help

shaun-mahood21:09:11

@ag: Is the problem you're dealing with related to doo, figwheel, or clojure-future-spec? Here are a couple of ideas to reduce the problem space and make it easier for other people to help - Reduce your dependencies to a few sets of minimum tests - maybe one with figwheel + doo, one with doo + clojure-future-spec, etc. - If there's a problem with clojure-future-spec, try the same minimal dependencies test but with clojure 1.9.0 alpha 13 instead - does it work with normal spec? I've found that this is usually my first troubleshooting step, and it often exposes some interaction that I didn't consider or shows me an error that was otherwise very difficult to find. At the very least it should point you in a direction to investigate further.

ag21:09:53

@shaun-mahood right, I wil try to disable some dependencies… it even maybe problem with ring…

ag21:09:59

¯\(ツ)