Fork me on GitHub
#clojurescript
<
2015-08-12
>
erichmond01:08:03

For those of us who want to experiment with the relay / om-next view of the world, what makes sense to start out with? Should we just follow the FB relay docs to get a feel for the architecture? Is there any CLJS stuff out there we can use to get the same architectural feel?

paradoxquine03:08:18

The falcor talks on youtube were helpful for me

jonas05:08:11

I don’t understand how to use js->clj with {:keywordize-keys true}. opts will be a sequence of rest args but the implementation destructures with :keys.

jonas05:08:46

ah, it works with (js->clj x :keywordize-keys true). Strange that the single arity call-site uses a map. https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L9325

a.espolov09:08:39

Guys please tell me how I can convey with a backend, this cljs code (js/alert "xyz!")? so that I was able to compile and run in the browser

jellea09:08:28

maybe make a alert function yourself on the backend? (set! js/alert #(prn %))

a.espolov09:08:12

@jellea: java.lang.RuntimeException: No such namespace: js

jellea09:08:49

@a.espolov: sorry presumed you where hosting on nodejs

domkm10:08:26

I'm getting a warning WARNING: cljs.core/bit-or, all arguments must be numbers, got [clj-nil number] instead. from https://github.com/ztellman/automat/blob/007118e8f54e96381833db3f05db257f93f0119d/src/automat/fsm.cljx#L605 . Breaking that line into multiple lines shows it's from the (int end) call. end should never be nil because it passes the number? check, right? Why is this occurring? CC @dnolen

dnolen10:08:02

@domkm: numeric inference isn't quite that strong - number? cannot help. However the int coercion should cover it anyway. So probably just a bug.

domkm10:08:40

@dnolen: Thanks. Is there a way to modify the code so that it can be inferred that it is a number?

dnolen10:08:32

@domkm: probably but also probably not worth it.

dnolen10:08:10

@domkm: actually I don't really understand why you think the problem is here. I don't see bit-or

domkm11:08:27

@dnolen: that's the line that cljs reports and when that line is split across multiple lines cljs reports the line with (int end)

dnolen11:08:27

@domkm: you are using cljx so I don’t know if you can trust the reporting lines

dnolen11:08:37

anyways the problem isn’t there, it’s with a bit-or op

domkm11:08:07

@dnolen I think cljx maintains line numbers but I will verify when I get back to my computer. I assumed int used bit-or internally. I'll look into it more later. Thanks for your feedback.

dnolen11:08:18

@domkm: ah, I’d forgotten that int was enhanced to inline expand to a bit-or with 0. that’s the bug actually.

dnolen11:08:41

previously int was function thus only coerced

mitchelkuijpers11:08:25

Are there any good suggestions for clojurescript logging libraries?

mitchelkuijpers11:08:50

https://github.com/ptaoussanis/timbre this looks pretty nice but there might be better alternatives?

domkm12:08:43

mitchelkuijpers: Shodan is worth checking out https://github.com/noprompt/shodan

martinklepsch13:08:13

@mitchelkuijpers: it’s pretty easy to roll your own using Closure logging stuff

mitchelkuijpers13:08:46

@martinklepsch: Yeah I did that before but I think its better to choose on and then provide pull request if i miss any functionality

mitchelkuijpers13:08:57

I am going with Shodan

martinklepsch13:08:12

I really like my Closure stuff 😄

mitchelkuijpers13:08:23

Maybe you should open-source it 😉

mitchelkuijpers13:08:30

I also use it a lot

mitchelkuijpers13:08:39

you can pretty easily use their autocomplete stuff

mitchelkuijpers13:08:03

I think a lot of people forget they have a lot of power from all the closure libs that just work

robert-stuttaford13:08:45

i wrote js apps with gclosure by hand for 8 months before i discovered clojure/script

robert-stuttaford13:08:00

it was a harrowing experience

robert-stuttaford13:08:16

but i did find a lot of great stuff in the library

mitchelkuijpers13:08:49

@robert-stuttaford: yeah I combine it with Om or React but there are a lot of goodies in there

mitchelkuijpers13:08:08

@martinklepsch: I do like the combination for server and client, might have to reconsider simple_smile

martinklepsch13:08:42

@mitchelkuijpers: probably easy to write a no-dependencies cljc logging lib from here on

mitchelkuijpers13:08:44

@martinklepsch: I might have to make a small lib from this gist if you don't mind

martinklepsch13:08:57

sure, it’s yours.

mitchelkuijpers13:08:22

I'll credit you 😉

martinklepsch13:08:23

@mitchelkuijpers: ping me when it’s up simple_smile

escherize13:08:24

is this an acceptable way to make uuids on the client:

(defn uuid
  []
  (letfn [(f [] (.toString (rand-int 16) 16))
          (g [] (.toString  (bit-or 0x8 (bit-and 0x3 (rand-int 15))) 16))]
    (.toString
     (goog.string.StringBuffer.
      (f)  (f) (f) (f) (f) (f) (f) (f)
      "-"  (f) (f) (f) (f)
      "-"  "4" (f) (f) (f)
      "-"  (g) (f) (f) (f)
      "-"  (f) (f) (f) (f) (f) (f) (f) (f) (f) (f) (f) (f)))))

escherize13:08:01

The algorithm is correct (afaik), but is there an obviously better approach?

mitchelkuijpers13:08:48

Now all I need is an awesome name for the lib

dialelo13:08:04

random-uuid was recently added to CLJS @escherize, you might want to use that instead

escherize13:08:17

Ahh, thanks dialelo

dialelo13:08:35

glad to be of help escherize

mitchelkuijpers13:08:03

@escherize: out of curiosity why do you need a uuid on the client?

escherize13:08:47

i use it to keep track of some state (maps) that the client creates before sending up to the server

escherize13:08:23

I guess I could use a counter

mitchelkuijpers13:08:38

@crisptrutski: c for the readerconditional and then loggs?

robert-stuttaford13:08:20

@martinklepsch: why use google’s logger instead of console.log?

mitchelkuijpers13:08:40

Googles logger gives you the possibility to log to other stuff

mitchelkuijpers13:08:43

like a server or a div

martinklepsch13:08:29

@robert-stuttaford: I haven’t fully explored the options there and logging to console seemed like the most intuitive thing — have you found something better than console logging?

robert-stuttaford13:08:52

i like the html div thing for mobile

robert-stuttaford13:08:05

querystring param enables in-page log, sort of thing

martinklepsch13:08:14

ah yeah, that’s nice

mitchelkuijpers13:08:22

They have some built in appenders

martinklepsch13:08:41

probably there should some alternatives to log-to-console!

robert-stuttaford13:08:28

mitchelkuijpers: where can i find these appenders?

mitchelkuijpers13:08:00

these a are a few

mitchelkuijpers13:08:04

pretty powerfull stuff

martinklepsch13:08:33

slog would also have been a neat name

rauh13:08:56

(Shameless self promotion): There is also: https://github.com/rauhs/klang

rauh13:08:58

@mitchelkuijpers: My klang library was actually first based on the design ideas of goog.debug.DebugWindow. Nowadays it's more powerful I think

crisptrutski13:08:42

i win the naming wars 😄

martinklepsch13:08:06

@rauh: klang is really nice, still want to use it in a project. It’s a lot more than a no-dependencies 50lines logging namespace though

rauh13:08:15

@martinklepsch: Yes but none of that is going into production ever. I only use it through macros (which are included in klang)

rauh13:08:30

There is a little section on how that's achieved ( https://github.com/rauhs/klang#with-deployment-to-clients )

cfleming14:08:19

Are there any examples out there of using CLJS to generate some JS for a page to do JQuery-style static page augmentation (i.e. updating some page elements on form element modification, client side validation etc)

cfleming14:08:44

I don’t want to go full-blown SPA but I’d like to use CLJS for the page scripting obviously

Lambda/Sierra14:08:25

@cfleming: It might be possible to make that work, but ClojureScript was never designed for that kind of gradual enhancement with small snippets of code.

cfleming14:08:21

@stuartsierra: That’s a bummer. I guess it’s JQuery for me, I was hoping to avoid that.

martinklepsch14:08:42

@cfleming: @stuartsierra you can make little jq-like wrappers with goog.dom etc.

martinklepsch14:08:36

@cfleming: @stuartsierra keep checking artifact size with each thing you add and make sure you don’t include/use stuff like persistent data structures etc — as far as I understand if you don’t use them they won’t be part of the build.

martinklepsch14:08:45

question then is though: will it be the same amount of fun? 😉

cfleming14:08:49

@martinklepsch: Hmm, that’s starting to sound like more complication than I was hoping for just to generate some small code snippets. I might just go with straight JS.

martinklepsch14:08:23

@cfleming: oh and there’s dommy of course

noprompt14:08:43

shodan is a pretty boring library. it's really just a thin layer over console with a couple of extra helpers. i've been meaning to improve it (along with other work i've done) but i've been limited on free time (of which i'm now devoting to reading/learning rather than coding so much). there might be a chance for clojurescript at my day job in the near future so i might be able to squeeze in some improvements then but for now i'm relying on the hope that others will send me PRs. simple_smile

noprompt14:08:02

i haven't experimented with klang but i think it has some interesting ideas.

noprompt14:08:01

i seldom use shodan because clairvoyant is typically what i need. for simple things i just use (.log js/console ...).

cfleming14:08:08

@martinklepsch: Thanks, dommy looks interesting, I’ll check that out. Looks like that should produce some pretty small JS too.

timgilbert15:08:38

The nice thing about shodan is that it uses a macro, so tracebacks in the console link to your original source file where you invoked it rather than the place in cljs.core where (.log js/console) is actually invoked when you use *enable-console-print!* or whatever it’s called

bhauman17:08:23

@cfleming: you can easily use jQuery from cljs. What I have do is use jQuery and when I'm done take stock of what I used JQuery for. And then I replace the needed jQuery functionality, which is normally limited to a couple features.

bhauman17:08:30

@cfleming: the idea being not to let this stuff get in your way. You can easily tune after the fact.

nullptr17:08:02

cfleming: cljs + closure library is awesome for this use case — given the benefits of advanced compilation, you’ll probably end up with less JS in the end as well

nullptr17:08:22

the only real downside is having to learn cljs + closure library, but i don’t think that’s gonna be a problem for you

nullptr18:08:22

i did a static content site with history/secretary, custom form handling, ajax, etc — ~40K total gzip size

dottedmag18:08:22

How does one debug macroexpansion in cljs? I'm getting a "WARNING: Use of undeclared Var seeitlater.main/G__7592 at line 10 src/seeitlater/main.cljs" and I suppose it is due to the fact my macro is expanded not as I expect. How do I see the expanded value?

bensu19:08:26

@dottedmag: if you are not using cljs.js macro expansion is done in clojure, not clojurescript. the best way to see what is happening is to start a repl in the your macro namespace and use macroexpand-1 and macroexpand

dottedmag19:08:06

@bensu: Indeed, it was wrong macroexpansion. (.. foo bar (baz blah)) confused the macro which expected (baz blah) to be a function call.

bensu19:08:50

.. is a macro itself and obeys all macroexpansion rules. you can also inspect what happens after .. with macroexpand

dottedmag19:08:30

Oh, right, and macros receive their arguments unexpanded, now I understand.

arohner20:08:01

does CLJS guarantee that nses with file-level effects are run in order, top-down?

martinklepsch20:08:57

@micha: thank you ❤️

val_waeselynck20:08:58

To the React/Om/Reagent/Quiescent folks: I've been experimenting lately with the concept of 'pluggable component'. Here's a Reagent implementation of it, I would love some feedback: https://github.com/vvvvalvalval/reagent-pluggable-components-poc

bensu20:08:46

@val_waeselynck you are handling pub/sub from the parent to the child. another normal pattern is to "bubble" events up through channels as well. do you have any ideas to fit this in your model?

val_waeselynck20:08:36

Yup you could totally extend this to EventTargets for example

val_waeselynck20:08:59

another way I've considered is to have an ::async/pipe-up recipe

val_waeselynck20:08:31

Basically, you create a local chan that is piped to a chan passed by the parent, and closed when the child unmounts

bensu20:08:56

yeah, that's the pattern I mean. great job, nobody (I mean the larger React ecosystem) has figured out how to structure components, local state, and events in a reasonable way.

val_waeselynck20:08:08

@bensu:

(defmethod make-plug ::async/pipe-up [[_] parent-chan]
  (let [local-chan (async/chan)]
    (->Plug local-chan #(async/pipe local-chan parent-chan false) #(async/close! local-chan))))

bensu20:08:26

we need people that take stabs at it

val_waeselynck20:08:38

This is still really questionable IMO. In a way, it's the management of your application state with the structure of your views.

val_waeselynck20:08:55

But it's still interesting to see how we can leverage React's virtual dom to help us manage our state in a declarative way. Basically, I'm letting React's diffing algorithm and mount abstraction do the heavy lifting here

nberger20:08:17

@arohner: do you mean if the top-level forms in of a namespace are evaluated in top-down order, or if ns evaluation (thus side effects) is done in dependency order? In both cases, I would say yes

nberger20:08:57

I also assumed (is (= "effects" "side-effects"))

dottedmag23:08:54

Is there a proper library which converts callback-based calls into core.async one? Something like cljs-asynchronize, but supporting more callback styles (node.js style, Chrome API style etc) and better implementation, so it does not choke on .. or (let) forms?