Fork me on GitHub
#clojurescript
<
2015-08-13
>
Petrus Theron03:08:53

Presented a talk on ClojureScript at the University of Cape Town yesterday during which we built a snake game. Slides, audio and gameplay now up: http://petrustheron.com/posts/sota-front-end-development-clojurescript.html Hopefully this is useful to others for teaching Clojure, especially the code (< 100 sloc).

asyncsrc03:08:46

This is nice, Petrus. Thank you for putting the slides, videos, and code together.

Petrus Theron04:08:51

:thumbsup: thanks, @asyncsrc. Regretfully no video recording. Audio and slides unsynchronised, but I'll post compiled game soon

asyncsrc04:08:57

ah, I saw the screen recording videos within the slides of intellij, which was the most important part for me personally. It would be nice to get a video recording of the presentation, but in most cases it seems like i need to follow along manually with slides anyhow since they’re hardly ever in focus in the video. But yeah, this is definitely awesome. Thanks again

escherize04:08:37

If i've got

(ns something.here (:require [goog.userAgent :as ua]))
(.log js/console (ua/getUserAgentString))
Will I need an extern?

escherize05:08:57

To answer my question: no

escherize05:08:27

Also, what are some good resources for learning the parts of google closure that are useful from cljs?

pupeno08:08:43

Has anybody ever tried running ClojureScript on the server to return a pre-rendered single-page-application on the first request?

danielcompton08:08:33

@pupeno: Reagent does this for it’s homepage IIRC

borkdude09:08:50

what's a good option for a typeahead when you're already using Reagent and Bootstrap?

borkdude09:08:58

I'll use jquery-ui as described in the Reagent cookbook

borkdude09:08:31

maybe even better, reagent-forms

martinklepsch10:08:32

@borkdude: there’s some autocomplete stuff in goog + twitter’s typeahead.js has recently been added to cljsjs

pupeno10:08:54

In re-frame, how do I deal with a handler depending on another? Something like having a handler called get-user that request the user from the server, another got-user, that gets the data and puts it in the state, but now I have one called get-friends. Get-friends should only be run after get-user/got-user finished but I don’t want got-user to run get-friends as it’s not needed most of the time? Should get-friends do a dispatch-sync of get-user?

escherize10:08:36

Thanks @greywolve - will check it out.

afhammad10:08:47

The latest Java update seems to have broken my cljs compiler. anyone else experience this?

niwinz11:08:22

with "openjdk version 1.8.0_51" everything works as expected

ordnungswidrig11:08:23

I’m using cljs.pprint but (pprint {:a {:b 1}}) does not generate any newlines.

ordnungswidrig11:08:36

I’ve bound print-pretty to true

sekao13:08:21

tools.reader currently cannot read the number literal 0 in clojurescript. not sure if this is worth making a ticket since it’s not a stable release yet though.

andrewmcveigh13:08:27

What version of cljs/tools.reader are you using? What platform, etc.?

sekao13:08:20

i’m using 0.10.0-alpha1, i’ll try again to see if i’m mistaken

sekao13:08:57

i’m just doing (read-string “0”) and getting “Invalid number format [0]”. other digits work fine.

sekao13:08:38

@andrewmcveigh: it must be an issue with my project because i can’t reproduce it in a new one

andrewmcveigh13:08:46

Yeah, not sure which read-string your calling, but (cljs.tools.reader/read-string "0”) is working for me.

rickmoynihan13:08:15

Is it possible to include a figwheel live-reload server into an existing app?

bhauman13:08:12

@rickmoynihan: You want to compose figwheel into an existing process?

rickmoynihan13:08:51

I have an existing server project - with no client side js yet... I want to add client side clojurescript to that project

bhauman13:08:39

@rickmoynihan: oh yeah that is straightforward

bhauman13:08:59

I would take a peek at the quick start

bhauman13:08:03

and the readme

bhauman13:08:16

to understand the moving parts first

bhauman13:08:29

no template needed

rickmoynihan13:08:36

so I've added lein-fighweel and lein-cljsbuild to the project.clj and put a cljsbuild section -- which appears to work (i.e. I can throw a cljs alert box up onto my page that is served when I run lein repl.

rickmoynihan13:08:47

What I don't have figured out yet is the live reload workflow

bhauman13:08:42

at first I would just use figwheel as a separate process

rickmoynihan13:08:57

yeah that seems easier

bhauman13:08:00

ie. lein figwheel

rickmoynihan13:08:07

when I tried it though it didn't seem to work

rickmoynihan13:08:23

presumably I need to include a figwheel script onto the page?

bhauman13:08:35

you don't have to load your compiled assets from figwheel you can load them from the server.

rickmoynihan13:08:38

when in the :dev env?

bhauman13:08:55

again I would look at the quick start

bhauman13:08:01

no real shortcuts

rickmoynihan13:08:17

yeah I have compiled assets working

rickmoynihan13:08:08

ok missed the quick start link - thought it was the README.md - thanks

bhauman13:08:12

shortcuts will drive you nuts

rickmoynihan13:08:48

this looks like what I was expecting to do... thanks

bhauman13:08:10

yeah I should have given you the link, and not assumed that you were wanting a short cut simple_smile

rickmoynihan13:08:13

damn - turns I already had it working

rickmoynihan13:08:48

I hadn't seen the figwheel process had actually connected...

borkdude14:08:42

@yogthos: is it possible to generate in the reagent-forms typeahead in inside the list items an anchor? our bootstrap css expects that

borkdude14:08:52

@yogthos: maybe with result-fn?

borkdude14:08:38

@yogthos: Looks like that works simple_smile

yogthos14:08:45

@borkdude: in general reagent-forms should be layout agnostic, it’s also possible to do multiple bind-fields calls binding to the same atom within a component, for example if you wanted to show different forms conditionally

borkdude14:08:45

@yogthos: the typeahead has a highlight-class

borkdude14:08:02

@yogthos: that works when you do arrow up and down, should it also work with mouse hover?

yogthos15:08:35

yeah that would make sense simple_smile

yogthos15:08:49

would have to hook in mouse enters/leaves events

sekao15:08:29

i think i found a way to lock up safari with cljs.js/eval by evaling a form defining a variadic function. if someone could try my test code in safari i would appreciate it https://github.com/oakes/boot-cljs-example/blob/master/src/app/core.cljs

martinklepsch15:08:07

@sekao: boot serve -d target/ watch speak reload cljs-repl cljs -sO none ?

sekao15:08:32

i just use boot dev

martinklepsch15:08:56

ah cool. didn’t know there’s an alias in the example proj

sekao15:08:13

@martinklepsch: and if you remove the & and try it again it loads fine?

martinklepsch15:08:06

@sekao: yes — logs nil once

sekao15:08:40

ok then i’m not going crazy 😃

pupeno17:08:12

I just created a re-frame project and it’s using figwheel but there’s no server side routing in the project. How do I make the server send the app when serving different URLs instead of just /

nullptr17:08:52

pupeno: easy way is to use # in your paths so everything gets to the same server path — otherwise, you’ll need to do some sort of path mapping — depends on server stuff how to do that, technically can just rewrite in apache etc.

pupeno17:08:46

nullptr: I just replaced secretary with silk and pushy to get rid of the #. In my main project, with compojure, it’s very easy to server the app no matter the URL and let the client do the routing. But for a blog post about this that I’m writing I’m using the re-frame template, which using figwheel with no server side, hence my question, how do I make figwheel serve the app for any URL that gets requested.

nullptr17:08:29

oh, in figwheel’s server you can pass it a ring handler which can basically do whatever it wants

mattparker17:08:49

Hey, I'm trying to set up modules. Right now I have

{:optimizations :simple
 :modules {
           :foo {:output-to "resources/public/js/foo.js"
                    :entries #{example.foo}}
           :bar {:output-to "resources/public/js/bar.js"
                       :entries #{example.bar}}}}
. example.foo depends on library1 and example.bar depends on library2. Both library1 and library2 end up in cljs_base.js, is that right? I expected foo.js to include library1 and bar.js to include library2. The other problem I'm having is that example.bar ends up in cljs_base.js instead of bar.js. Any ideas what's going on?

nullptr17:08:32

does example.foo :require example.bar?

nullptr17:08:12

i figured it didn’t, though it would explain everything :)

bensu17:08:42

@mattparker: I don't have any experience with modules, but if I remember correctly, in the example there are three parts: example.bar, example.foo, and common.code-to-both

bensu17:08:55

and then there is a small dependency ordering

bensu17:08:26

yeah I remember that, but I'm just pointing you to the wiki in case the :depends option applies to your situation.

bensu17:08:38

(that's all I can offer simple_smile )

mattparker17:08:00

nah none of the namespaces depend on each other. Thanks though!

nullptr18:08:47

fwiw your expectations of the end result appear correct. at least that’s how closure modules have worked for me via JS build paths (plovr).

mfikes18:08:02

@sekao: There can be subtle problems with reading 0 related to *uncheked-if*. See https://github.com/mfikes/replete/issues/8#issuecomment-119052347

jpmonettas18:08:43

hi guys! I'm looking for a persistent collection for clojurescript that acts as a ring-buffer or sliding-buffer

jpmonettas18:08:18

but I would need to migrate that to cljc and replace a couple of things

rauh18:08:05

@jpmonettas: Clojure (and cljs) has queues if that works for you

jpmonettas18:08:47

but I need a fixed length one

jpmonettas18:08:11

so if a push one more than supported size, it drops the first

jpmonettas18:08:20

something like core.async sliding-buffer

rauh18:08:01

Gotcha, wasn't sure if you actually needed that.

jpmonettas18:08:06

exactly like amalloy ring-buffer but that works on cljs

mfikes18:08:52

@sekao: If you evaluate (do (ns foo.bar) (def x 3)) then x will not be defined in foo.bar in ClojureScript. In your “lock up Safari” example, that code complains a lot for me in things like Planck and Replete in the analyzer, perhaps as a consequence of the use of &. One suggestion would be to ensure cljs.user is created before doing the eval.

sekao18:08:01

@mfikes i pushed a change to the example that evals them separately but Safari still locks up https://github.com/oakes/boot-cljs-example/blob/master/src/app/core.cljs

sekao18:08:31

@mfikes the weird part about the (read-string “0”) problem is that it seems to work fine when i build with advanced optimizations, it only seems to fail when i’m in dev mode. but since i can’t reproduce it in other projects i am just ignoring it for now...

mfikes18:08:18

@sekao: When Safari locks up, does it use a lot of CPU?

sekao18:08:51

yes, there is an item in activity monitor called Safari Web Content with high cpu usage

sekao18:08:08

like 80% and it says it is not responding

mfikes19:08:25

There was a small perf problem we discovered with defn and Safari for cljs.js that can be worked around via :static-fns true: http://dev.clojure.org/jira/browse/CLJS-1381

sekao19:08:10

@mfikes: yeah i noticed it is quite slow with defn in general but it seems like variadic defn is a separate issue, as it locks up indefinitely

mfikes19:08:31

@sekao: Yeah, I can repro your problem with :static-fns false in Planck.

mfikes19:08:08

@sekao (defn hello [& args]) ultimately kills it

sekao19:08:59

oh maybe they are indeed the same issue, i think i got safari to lock up without the &

mfikes19:08:16

@sekao: The good thing is the WebKit team already know about the defect (it has been known for a good chunck of a year.

sekao19:08:46

i just cleared my cache and the non-variadic defn worked fine, so it may have been using my variadic test just now

sekao19:08:19

that’s good to hear regarding the webkit team

mfikes19:08:33

@sekao: Planck (which is also based on JavaScriptCore) cannot evaluate (defn hello [& args]) unless I build it with :static-fns true to work around the JavaScriptCore bug.

sekao19:08:20

i actually recall testing it on http://clojurescript.net and it worked fine in safari. i thought they were using bootstrapped cljs

mfikes19:08:44

Joel Martin updated http://clojurescript.net to reflecct what we learned about :static-fns true

mfikes19:08:14

It was also exhibiting slowness for defn in Safari until he addressed that.

sekao19:08:27

@mfikes: thanks, that indeed fixes the issue in my project

jpmonettas19:08:48

@mfikes: I'll check that. Thanks!

jpmonettas19:08:57

@nberger: Hey, that was quick! Thanks a lot

bensu20:08:04

@nberger: cool! I skimmed over the PR and I would recommend a project like ring-buffer to test on node (not only it's more likely to be installed but it's also a better fit)

nberger20:08:32

@bensu: Thanks. Why do you think it's a better fit? Agree with the likelihood of node being available, but don't think it's something critical... Anyways, I'll wait until @amalloy reviews the PR.

bensu20:08:57

@nberger: not critical at all. Node is faster (both upstart and runtime), more stable, and has fewer quirks than Phantom. The only reason not to use Node is when you need a dom to manipulate (which I'm guessing ring-buffer doesn't).

nberger21:08:43

@bensu: well, that's not the only reason: another reason could be for example if you simply started using phantom because you consider it won't be much difference using node in that particular project. For example in this case, I'm really not worried by phantom being slower in running a test suite that takes 0.11 secs to run in my machine.

bensu21:08:00

I agree, when I say the only reason I mean: "if you want to take the time to decide, node will be a better fit". In many cases, such as this one, the decision might not be worth it, as you just said simple_smile

nberger21:08:09

@bensu: I'd be very happy to change the cljs test config to node if the project maintainer considers it is important. Feel free to chime in the PR to add your point of view, that would be very helpful for the maintainer to take a decision.

bensu21:08:18

@nberger: sure, I'll give it a go after the PR settles. the project looks cool and I've been thinking about something like this to implement a somewhat generic undo component.

bensu21:08:23

thanks for porting it to cljs!

nberger21:08:21

@bensu: cool! Go ahead, it has just been merged simple_smile

bensu21:08:24

@nberger: just did it, as you said the change is not worth at all.

bensu21:08:03

@nberger: when you include the lein startup time, the difference is so small is in the rounding error

bensu21:08:12

the upside is that it worked only by changing the compiler's config, which is always a relief for a library author simple_smile

tel22:08:20

anyone happen to be really familiar with running cljs tests via figwheel? simple_smile

tel22:08:36

I’ve got some really weird behavior

tel22:08:53

I’m sure it’s a flaw in my configuration

tel22:08:13

but I don’t have my head around how it all works well enough yet to get it to go through

tel22:08:50

the short of it being that whenever I edit a non-test file to add new symbols they get added but an old version of the tests is run against them

tel22:08:05

and whenever I update the tests the newest test version is run but against old symbols

tel22:08:17

I’m running it like lein figwheel app test

tel22:08:27

atop something not dissimilar from the reagent template configuration

tel22:08:49

and I think what must be going on is that the two builds are conflicting somehow

tel22:08:02

but I can’t really figure out how or why

pandeiro23:08:55

@tel: faced a very similar problem with boot-cljs; i created a simple repro here: https://github.com/pandeiro/cljs-test-issue

tel23:08:58

is cljs.test preferred over cemerick.clojurescript.test?