Fork me on GitHub
#clojurescript
<
2016-04-17
>
zentrope07:04:49

How do you figure out that two objects are instances of the same (defrecord) type?

mikethompson07:04:00

Use type?

cljs.user=> (defrecord A [a b])
cljs.user/A
cljs.user=> (defrecord B  [c d])
cljs.user/B
cljs.user=> (= (type (->A 1 2)) (type (->A 2 3)))
true
cljs.user=> (= (type (->A 1 2)) (type (->B 2 3)))
false

zentrope07:04:19

Huh. That wasn’t working for me.

mikethompson07:04:02

The above was via: http://clojurescript.io/ (so that's bootstraped cljs, but I would expect the Java tool chain to produce the same).

zentrope07:04:50

Yeah, I think it works. I must have messed something up elsewhere. Thanks!

zentrope07:04:08

Yeah, I had a “do not” on the if clause that should have been “do”. Oy.

urbanslug10:04:03

What did you guys use to learn clojurescript?

borkdude12:04:53

@urbanslug: mainly normal Clojure books and then just do it, for example use Reagent

urbanslug12:04:02

@borkdude: Heh, it seems just doing it is the way with most langs that are on the rise.

urbanslug12:04:12

Using Om though

bojan.matic12:04:01

how well does clojure handle js interop, for example when you need to interact with a stateful api

bojan.matic12:04:08

something like camera or canvas

bojan.matic12:04:44

is there any pain?

ctford14:04:22

@bojan.matic: In my experience, very little syntactic pain, but sometimes the mutable/immutable way of doing things takes some thinking about.

ctford14:04:54

Does anyone know if there's a way to override the exported name of a CLJS function in JS? I have a CLJS fn with a -> suffix, and it gets encoded as a _gt, which isn't very nice.

ctford14:04:37

@bojan.matic: You might find it useful to try and push the mutable bits to the "edge", and use immutable values throughout the main CLJS code.

akjetma16:04:44

@ctford: (defn ^{:export lol} lol-> [] “haha”)

akjetma16:04:55

note that lol would be the exported function though, rather than your.namespace.lol

ctford16:04:52

oh, right. I had missed that.

akjetma16:04:45

yeah, i just checked it out myself. i wonder if there could be issues with this and stuff… if it’s a pure function you’re probably good though

ctford17:04:03

Yeah, all pure for the case I'm looking at.

grav19:04:04

From the cljs quickstart guide, there’s a paragraph saying

Note: Under Node.js there is little reason to use advanced optimizations. While advanced optimizations does apply performance related optimizations, these are now largely obviated by optimizations present in modern JavaScript virtual machines like V8, SpiderMonkey, and JavaScriptCore. For Node.js, :simple or :none optimizations suffice and using them removes the need for extra steps like supplying an externs file.
Does this still hold? If you’re targeting modern browsers then why at all use advanced optimizations?

isak20:04:29

@grav for file size, which you dont care about on the server

zentrope22:04:35

If I have a type my.foo.Record, how to I create a new instance what takes a param?

zentrope22:04:12

(new mytype param) gives me “Record is not a constructor”.

darwin22:04:50

(my.foo.Record. param)

darwin22:04:01

(note the dot)

zentrope22:04:08

I don’t have the actual name: I’m looking it up in a map.

darwin22:04:43

aha, there was a way, but I don’t remember from the top of my head

zentrope22:04:25

Heh. I’m trying to find something like cljsfiddle that just gives me a repl.

zentrope22:04:34

Oh, I think it works. I think I was just returning a (new thing param) to a thing that then called “new” on it again.

Nicolas Boskovic23:04:47

How would I do something like this in cljs?

Nicolas Boskovic23:04:41

I've tried doing (.dropdown ($ ".blabla") {:key val :key2 {:key3 val2}}) but it's not quite working

darwin23:04:28

(.dropdown (js/$ ".blabla") #js {:key val :key2 #js {:key3 val2}})

darwin23:04:57

using {…} will give you cljs map which cannot be directly consumed by js code

darwin23:04:29

please note that #js is not deep (for good reasons) @nnbosko ^

Nicolas Boskovic23:04:27

Deep in what sense?

darwin23:04:59

do you see that second #js? it has to be there for nested map to be constructed as plain js-obj

darwin23:04:21

also val and val2 must be plain js values, not cljs things

darwin23:04:02

@nnbosko: ah, sorry, now I look again and you don’t have nested objects in your example, sorry my mistake

darwin23:04:38

ah, you actually have, sorry too late

Nicolas Boskovic23:04:39

I got it running