Fork me on GitHub
#clojurescript
<
2017-02-21
>
anmonteiro00:02:00

@qqq clojure.tools.reader

mfikes00:02:09

@risto FWIW, you can do

(cljs.spec.test/check `hello)

PB02:02:01

Hey all. I'm somewhat of a CLJS newbie. I'm trying to play around with gundb, however I notice that it's not part of the cljsjs. I'm very happy to add it. I just require a little direction

deas08:02:47

Anyone working with closure compiler sources?

thheller08:02:13

@deas what do you mean by that? the java sources?

deas08:02:28

@thheller Yes, java sources.

thheller08:02:03

I have worked a bit with those

deas08:02:14

Wondering what's the trick to get it into IntelliJ so things compile and behave as you'd expect.

thheller08:02:35

hmm I just imported the pom file?

thheller08:02:49

but most of my development wasn't modifying the actual compiler sources

deas08:02:57

Does not work for me. Intelli does not like those <module>pom-main.xml</module> entries. Next issue I hit is duplicate sources due to generated sources.

thheller08:02:02

I wrote a compiler pass that just uses some internal hidden APIs

thheller08:02:21

hmm let me open the project and check

deas08:02:50

Thing is: I'd like to get me feet wet on commonjs stuff. Which seems to be quite in flux these days.

thheller08:02:17

yeah you are right, can't compile anything

thheller08:02:42

think I just referenced the sources for my stuff, never actually tried to compile it

deas08:02:54

Weird structure. Guess we can't blame Jetbrains. 🙂

thheller08:02:54

it compiles fine with maven so there must be a way 😉

deas08:02:04

Hehe, that was my thinking as well. Looks a bit like an exploit to me. 🙂

thheller08:02:32

hehe they have special instructions for eclipse in the readme

thheller08:02:36

maybe those apply as well

deas09:02:38

Maybe it's the easiest route just to d/l and use eclipse. 🙂

thheller09:02:30

maybe just ignore the maven bits and setup the project manually

Aron09:02:12

if anyone has the inclination, i would be really happy to hear some harsh criticism of this https://github.com/ashnur/cljs-combo-network/blob/master/src/combo_network/core.cljs particularly about stuff i could do differently without hurting performance. but i am open to anything new. I use def at a lot of places because those variables will be in the state for the react stuff eventually, not globals, but i already like to change them and see how the graph behaves differently. My main pain points are the ticked and the update functions, this approach is coming from d3 but I don't like it too much, especially because it's so easy to mess up the drawing algorithms. I am looking for some better but still fast abstractions, if there are any. Thanks in advance 🙂

Aron09:02:49

should i add comments?

fernandohur09:02:37

Would be useful to know what the project is about @ashnur 🙂

Aron09:02:59

it's graph visualization

thheller09:02:28

@ashnur I'm too busy but I would recommend throwing your performance assumptions out of the window and rewrite it completely with CLJS idioms in mind

thheller09:02:30

then compare

thheller09:02:46

ie. less native JS interop, more cljs.core

Aron09:02:17

i have to use js interop if i want to use d3 internal algorithms

thheller09:02:42

that doesn't seem like you want a set?

Aron09:02:16

@thheller you said you are busy, for me this is not urgent, if some other time you would have more time to pick on it 🙂

Aron09:02:52

i don't even know what that does, let me check 😄

Aron09:02:45

@thheller yes, that's my mistake, that's dead code. removing it

Aron09:02:23

thanks 🙂

Aron09:02:13

i should also remove the mess from draw-message, i just didn't know which direction i will go

Aron10:02:08

removed some more code and added some comments

andrea.crotti12:02:04

assuming a project has both backend and frontend in Clojure(script)

andrea.crotti12:02:15

is it worth to have it all in the same project?

andrea.crotti12:02:05

You can probably find ways to share code anyway, and maybe with a single project you might add other complications for deployment or libraries changes

andrea.crotti12:02:27

so there would be more flexibility in having them separate I guess

andrea.crotti12:02:15

but things like Chestnut by default add both compojure and all the clojurescript stuff for exampe

plexus12:02:25

Having them together will in general be easier. Your backend and frontend will evolve together and so having a shared history makes things easier.

plexus12:02:39

There are benefits to having it separate as well. Main reason would be if you're deploying them separately and want to be able to ship features in frontend without having to redeploy the backend and vice versa

plexus12:02:03

But in general unless you have separate teams doing front and back I would probably keep them together in one repo

dnolen13:02:14

@andrea.crotti it’s hard to think of common cases where having them separate is better - unless it’s a large pre-existing project and integration is impractical for some reason

nicoschneider14:02:20

Hey everybody, I’m trying to write a reagent frontend using re-frame and sente. I got everything working as described in the various readmes and issue comments in the sente repo, but I’m struggling with my authentication layer which uses buddy-auth‘s token backend. Before trying to integrate sente, I got it working via cljs-ajax (sending an Authorization header with the token) – how do I best approach this? Should I only connect when I have a token (which would mean acquiring the token in a more ‘traditional’ way, right?), or use sente’s chsk-reconnect! and implement the auth flow with sente, too? Another problem: When using the ajax-opts option in sente/make-channel-socket!, I can’t seem to get it to send the Authorization header, while params work as advertised

nicoschneider14:02:49

(If this is not the right place: is there a more specific channel I can post this question to?)

hlolli14:02:02

@nicoschneider I think buddy-auth sends a cookie, which adds some session data to every request from the client. Not sure if that travels with websocket connection, I doubt that it works, except maybe authenticating initially and establish a websocket connection and keep it without looking for the session data again. As for sente, I found it simpler to just use http-kit which sente bases most of its functionality on, in case sente makes your hairs gray.

nicoschneider14:02:08

@hlolli thanks, but I’m pretty set on sente (or similar?) since I have dreams about re-frame + websocket events. I use aleph as the http server (more because of the novelty than anything else, really), and it works so far. The cookie seems to work over ws connection – so you’re saying I can grab user identity info from the cookie in sente’s :user-id-fn?

nicoschneider14:02:50

(minus the naming in example code, nothin really makes my hair grey with sente :))

negaduck14:02:17

hello. Does anyone run cljs code in ios safari? I’m not sure, but it seems it just loads resources in a random order and I get errors because of this, different set of errors on every page reload.

hlolli14:02:00

I have a middleware

(defn authenticate
  [handler]
  (friend/authenticate handler
                       auth-config))
it will fetch the data from the cookie, I think the function friend/authenticate is bit magical to me, but works.

hlolli15:02:10

and auth-config

(def auth-config
  {:allow-anon? true
   :login-uri "/login"
   :default-landing-uri "/"
   :unauthorized-handler (wrap-json-unauth default-unauthorized-handler)
   :unauthenticated-handler (wrap-json-unauth friend/default-unauthenticated-handler)
   :credential-fn check-credentials-and-store-session
   :workflows [(workflows/interactive-form)]})

Pablo Fernandez15:02:42

I just added the cljsjs/ag-grid package (which I wrote) to a project and it clearly defines cljsjs.ag-grid but when I try requiring it, I get an error: "No such namespace". Any ideas why this could be happening?

mrchance16:02:24

anmonteiro: Absolutely awesome! Thanks for your work on lumo, I use it more and more!

anmonteiro16:02:30

Thanks, appreciate it. Have fun with the new release :-)

anmonteiro15:02:12

^ you can now compile CLJS projects (with Google Closure optimizations too!)

negaduck15:02:08

could someone help me to figure out why, for example, goog/asserts.js loads before goog/util.js where the goog.debug.Error is defined so I get TypeError: undefined is not an object (evaluating ‘goog.debug.Error’): https://www.dropbox.com/s/o0r9hre942il1po/Screen%20Shot%202017-02-21%20at%2018.24.54.png?dl=0

negaduck15:02:31

in ios safari only

bbss15:02:07

which cljs version are you using @negaduck ?

bbss15:02:15

okay, sorry don't know then

PB16:02:35

Hey all. I'm trying to create a cljsjs package ( https://github.com/cljsjs/packages/pull/1007 ). However, when trying to minify file for production use I'm getting the following error:

Minifying gun.inc.js
Feb 21, 2017 11:02:26 AM com.google.javascript.jscomp.LoggerErrorManager println
SEVERE: /home/peter/.boot/cache/tmp/home/peter/code/cljs-packages/gun/erw/u2qisy/cljsjs/gun/development/gun.inc.js:676: ERROR - Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly. If you are targeting newer versions of JS, set the appropriate language_in option.
					lex: ((lex) || (lex))? Gun.is.rel.ify(lex) : lex,
					                                                                     ^

Sifting output files...
I'm not really sure what to do. Would someone point me in the right direction. I have looked at specifying the language_in option, however literally none of the other cljsjs projects do this. So I'm not sure that it's the correct direction

borkdude16:02:35

What’s the goto way to ‘merge’ a cljs map with a JS object? I write (clj->js (merge (js->clj obj) m)), but wonder if there is a better way

anmonteiro16:02:54

@borkdude I use goog.object/extend

anmonteiro16:02:18

You wanna avoid clj->js whenever you can

dnolen16:02:55

it’s needlessly inefficient

dnolen16:02:13

I mean there’s no way really to make it more efficient

dnolen16:02:25

and using for merge seems gratuitous

anmonteiro16:02:47

@borkdude if you know your maps are shallow, it should be OK

anmonteiro16:02:22

Now if you're nesting structures you'll pay the perf cost

borkdude16:02:56

yeah, I figured it would be more costly. I almost went for Object.assign, but this didn’t feel right. goog.extend it is

dnolen16:02:10

Object.assign needs to be polyfilled

borkdude16:02:40

@anmonteiro This should get me to the newest Lumo right? npm update -g lumo-cljs

dnolen16:02:40

(gobj/extend js-obj (clj->js some-map))

borkdude16:02:12

@dnolen Thanks and in the second argument I often can get away with a #js literal, which would be even cheaper

dnolen16:02:13

but if some-map is only used by this code, I would just use a #js literal

dnolen16:02:24

@borkdude you read my mind

anmonteiro16:02:04

@borkdude also hold on to the arg you pass to gobj/extend, it mutates it

anmonteiro16:02:26

I'm not too familiar with NPM but I pushed 1.2.0 last night

dnolen16:02:45

(doto js-obj (gobj/extend …))

dnolen16:02:50

is what I do

borkdude16:02:05

oh yes, that again 🙂

borkdude16:02:26

I’m not an NPM guru myself, but it doesn’t update :-S

anmonteiro16:02:17

Weird, try uninstalling first maybe?

borkdude16:02:08

Gotcha, I had an old lumo not installed by NPM somewhere.

borkdude16:02:41

lumo -e "(doto #js {:a 1} (goog.object/extend #js {:b 1}))” works 🙂

richiardiandrea16:02:39

@petr I would try directly on either the GitHub issue pages or #cljsjs

PB16:02:11

I was silly not to think of that channel. THank you @richiardiandrea

mrchance16:02:07

@anmonteiro Since you're here... I noticed that when I use the cljs variant of core.async (andare), script startup times go up a lot, up to 40 seconds for simple scripts. Is that expected? Is there any way to speed it up?

anmonteiro16:02:03

@mrchance it's because of the time it takes to compile the core async macros

anmonteiro16:02:31

Use lumo -K for auto cache or lumo -k your-dir for manual cache

mrchance16:02:40

Mh, thought so, those things are serious business 😉

anmonteiro16:02:40

Subsequent runs will use cached JS

mrchance16:02:54

oh, nice, will try that. Thanks!

mfikes16:02:29

@mrchance There was also a big perf regression that really hits Andare hard under self-hosted ClojureScript. It was fixed in 1.9.473 http://dev.clojure.org/jira/browse/CLJS-1932

mrchance16:02:14

@mfikes Haha, this slack is so awesome, it's like the author of every cool library I use is here to help 😉 Thanks, I'll give it a shot! Probably not in lumo yet though, right?

mrchance08:02:58

Good point, I mainly use it to run scripts picard-facepalm

mrchance08:02:02

It's already in!

mfikes16:02:18

Start up Lumo—it indicates the version of ClojureScript in its banner.

peeja17:02:34

I'm finding that the :fn-scope of the macro &env is empty when I'm in a function with multiple or variadic arity. Is that expected, or a bug?

peeja17:02:42

That is, if I have this macro:

peeja17:02:50

(defmacro fn-scope []
  `(quote ~(:fn-scope &env)))

peeja17:02:03

And these calls:

peeja17:02:08

(defn fn-scope-single-arity [a]
  (prn (fn-scope)))

(defn fn-scope-multi-arity
  ([a] (prn (fn-scope)))
  ([a b] (prn (fn-scope))))

(defn fn-scope-var-arity [& as]
  (prn (fn-scope)))

peeja17:02:40

(fn-scope-single-arity 1)
(fn-scope-multi-arity 1)
(fn-scope-multi-arity 1 2)
(fn-scope-var-arity 1 2 3)

peeja17:02:23

the first gives me [{:name fn-scope-single-arity, :info {…}}], while the rest all print []

peeja17:02:50

(I realize I'm dabbling in the dark arts to begin with here…)

thheller18:02:05

@peeja I don't think there is an official API for this stuff. so it is neither expected nor a bug.

thheller18:02:29

the analyzer data is a bit chaotic in many places

peeja18:02:59

Yeah, that makes sense

thheller18:02:34

@peeja also be careful with this stuff, (defn fn-scope-single-arity [a] (let [foo 1] (prn (fn-scope)))) is another scope

thheller18:02:53

not sure what you are after though 😉

peeja18:02:10

Yeah, I know, it gets tricky 🙂

peeja18:02:58

We're using a macro to annotate Om components with the name of the function for styling. It's a nice trick, and it's been working fine for months, but apparently we've never tried to make a component function variable arity before.

tech_hutch21:02:09

I'm going through the guide at https://clojurescript.org/guides/quick-start. In the "Running ClojureScript on Node.js" section, I'm getting an error when I try to run my code with node:

W:\Personal\Coding\Discord\selfbot-cljs\out\goog\dom\dom.js:2242
  this.document_ = opt_document || goog.global.document || document;
                                                           ^
ReferenceError: document is not defined
    at new goog.dom.DomHelper (W:\Personal\Coding\Discord\selfbot-cljs\out\goog\dom\dom.js:2242:60)
...etc.

tech_hutch21:02:25

I know there's no document in node, of course, but why is Google Closure looking for it?

thheller21:02:16

@tech_hutch something in your code (or dependencies) imports it most likely

tech_hutch21:02:20

You mean Google Closure, as a whole? I thought ClojureScript itself used it?

thheller21:02:43

no i mean goog\dom\dom.js specifically

tech_hutch21:02:59

I'll post my code. It's very short.

thheller21:02:58

is there anything else on "src"?

dnolen21:02:17

@tech_hutch you’ve elided the stacktrace which tell us which file is trying to load goog.dom

tech_hutch21:02:31

Oh, I just realized something.

tech_hutch21:02:47

In "src", I have both "selfbot_cljs" and "selfbot-cljs", which both contain a "core.cljs". I renamed that folder at one point, because I remembered it saying somewhere that the folder path had to have hyphens replaced with underscores. I don't know how I ended up with both folders, but that's probably the problem.

tech_hutch22:02:43

Thanks for the help. (I haven't tested it yet, though, since I'm heading home now.)

PB22:02:02

Hey all. i'm a complete Js newbie. Would anyone be so kind as to tell me if this is the correct way to do things in cljs? https://www.refheap.com/9d248106209b20cccf68299d5

PB22:02:30

I just put it inside of a reagent view because it seemed like a simple environment to just mess around in

darwin22:02:54

(js/Gun.) compiles to new Gun() not Gun()

PB22:02:17

Ah, So I would want (Gun.) then?

darwin22:02:39

no just (js/Gun)

darwin22:02:58

you call a function

PB22:02:56

Is the (.. notation common?

darwin22:02:23

I don’t know, but I don’t use it much and I don’t see it in others’ people code much

darwin22:02:04

btw. your usage of js-obj also looks suspicious to me, js-obj takes arguments k1 v1 k2 v2 … kN vN, not a map AFAIK

PB22:02:37

I should have told you. This doesn't work 😕

PB22:02:53

I'm trying to recreate that example

thheller22:02:55

looks like you are almost there, I see some mistakes but its close 😉

PB23:02:46

@darwin do you prefer to use (doto gun ...)

thheller23:02:38

you can also use -> but .. is safe and nice to use

PB23:02:40

@thheller one thing I'm unsure of how to do is gun.get('mark').on(function(data, key){console.log...}

thheller23:02:10

(on [data key] is missing an fn so (on (fn [data key] ...

darwin23:02:11

@petr doto works differently, it does not chain calls, it operates on the original object

PB23:02:32

@darwin I assumed it would work similarly to the java interop

thheller23:02:43

(-> gun (.get 'mark') (.put #js {:name "mark"})))

thheller23:02:18

(.. gun (get 'mark') (put #js {:name "mark"})))

PB23:02:28

why the # ?

thheller23:02:40

same thing really, I prefer ->

darwin23:02:03

I also prefer ->

PB23:02:14

Hmm fair enough

thheller23:02:26

#js is a tagged literal shortcut to create a js-obj

PB23:02:12

Oh cool

PB23:02:19

That helps a lot, thank you!

PB23:02:13

So if I create a var. I should be able to interact with it in the console?

thheller23:02:37

but the def you create in the ns

PB23:02:55

Yep, I just did that

PB23:02:09

Thank you thheller and darwin . I'll play with this a little longer

thheller23:02:20

have fun 😉