Fork me on GitHub
#clojurescript
<
2016-03-16
>
fasiha06:03:43

Should goog.array.binarySearch be behaving like this, in a cljs repl?:

cljs.user=> (goog.array.binarySearch [1 2 3] 2 compare)
-1
cljs.user=> (goog.array.binarySearch [1 2 3] 5 compare)
-1
Basically, no matter what the second or third argument is, it seems to return -1.

nidu06:03:26

@fasiha: do goog libs work with cljs collection well? Shouldn't it be #js [1 2 3]?

fasiha06:03:38

@nidu 👍 👌 you got it, thanks!

fasiha06:03:31

I will now see if subvec/`rsubvec` are faster or slower than (goog.array.binarySearch (clj->js v)… simple_smile

nidu06:03:31

@fasiha: Found some performance bottleneck?

fasiha06:03:53

Just trying to get a feeling for these magical Clojure/Script data structures. Vectors that are implemented with trees, and other apparent absurdities 😄

bwstearns08:03:52

Hey all, I'm stuck on the right way to get the google maps API. I've got it in my deps (https://github.com/BWStearns/hrbr/blob/master/project.clj#L41) and I think I'm requiring it properly (https://github.com/BWStearns/hrbr/blob/master/src/cljs/hrbr/comps.cljs#L7) but I'm still getting clojure.lang.ExceptionInfo : No such namespace: cljsjs.google-maps, could not locate cljsjs/google_maps.cljs, cljsjs/google_maps.cljc, or Closure namespace "cljsjs.google-maps" I see the github page (https://github.com/cljsjs/packages/tree/master/google-maps) says "The Google Maps js API will still need to provided through some other mechanism" but I'm not sure if that's what I'm running into or what that other mechanism would be. Sorry to bug everyone with a dependency problem (I know code problems are more fun).

martinklepsch08:03:11

@bwstearns: Since Google Maps is externs only it does not provide any (fake) namespaces to require

martinklepsch08:03:33

I'm not entirely sure about this but I think just including the dependency will include the externs in compilation

martinklepsch08:03:25

@bwstearns: also just to make sure: you will still need to load the google maps JS API on your own — since these files are dynamic they cannot be packaged as a CLJSJS package

bwstearns08:03:50

@martinklepsch: "does not provide any (fake) namespaces", what do you mean by fake namespaces?

bwstearns08:03:34

So does that mean that I should just have <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script> in the HTML?

martinklepsch08:03:34

Most other CLJSJS libs provide a fake namespace like cljsjs.react that will (if you require it) add the react code to your build. Since this is not a real namespace/closure module you will still access it via js/React — that's why I called them fake namespaces

martinklepsch08:03:12

@bwstearns: yes, for google maps something like this is necessary.

bwstearns08:03:53

@martinklepsch: ok, and then I can just access that in cljs files with something like js/google.maps.mapFoo?

bwstearns09:03:22

@martinklepsch: thanks for the help and the explanation

martinklepsch09:03:46

> ok, and then I can just access that in cljs files with something like js/google.maps.mapFoo? yes simple_smile

martinklepsch09:03:59

sorry didn't see the earlier message @bwstearns — did you get it working?

george.w.singer13:03:20

My goal: Construct a ClojureScript function that takes a string s and returns the unique channel with the name (str s "-chan") (if the channel doesn't exist, then create it). Here is my attempt:

(defn string-channel 
      [s]
      (let [chan-name (symbol (str s "-chan"))]
        (defonce chan-name (chan))
        chan-name))
This yields an error. How do I accomplish this goal in cljs (without the use of eval, etc)?

exupero13:03:54

@george.w.singer: You’ll need to use a macro. (defonce chan-name (chan)) will create a var named, literally, chan-name.

george.w.singer13:03:03

Ok. Here is my attempt. I'll see if it works

(defmacro string-channel 
  [s]
   (do
    (defonce ~(symbol (str s "-chan")) (chan))
   ~(symbol (str s "-chan"))))

cky13:03:37

Your argument to string-channel will be evaluated twice. :-(

george.w.singer14:03:02

in any event: I get error "first thing to def must be a symbol"

joost-diepenmaat14:03:54

you want to quote the (defonce…) expression

joost-diepenmaat14:03:10

`(defonce ~(symbol (str s "-chan")) (chan))

joost-diepenmaat14:03:34

or even the whole (do … ) expression.

joost-diepenmaat14:03:14

but since you’re not actually using the name directly, you could also store all the chans in a map in an atom

joost-diepenmaat14:03:22

and then you don’t need a macro

joost-diepenmaat14:03:37

(defonce channels (atom {}))

joost-diepenmaat14:03:29

(defn string-channel [s] (swap! channels update s (fn [existing] (or existing (chan)))) (channels s)) or something like that

urbanslug14:03:20

What do you guys use to test your async calls?

george.w.singer14:03:10

@joost-diepenmaat: quoting the do block worked

george.w.singer14:03:54

@joost-diepenmaat: any reason to prefer the atom solution? Is is it just avoiding macros, which can be a pain in clojurescript?

joost-diepenmaat14:03:12

mostly because macros are a pain

joost-diepenmaat14:03:28

but also adding random vars in the namespace is a bad idea

george.w.singer14:03:02

@urbanslug: here is a template I often use for async testing:

(deftest <fn-TEST
  (async done
    (testing "Optional description of test."
      (go 
        (let [input-data "Input data for <fn you are testing."
              expected   "Expected value of your <fn"
              actual     (<! (<fn input-data))]
          (is (= expected actual)))
      (done)))))

george.w.singer14:03:21

Where <fn is a function that returns a channel

dhruv115:03:07

I m looking for a material design templates. I am new to building website and I like clojure/clojurescript and react-js caught my eye. (re-frame) can anyone point me to a good templates I can easily add to my site

peeja15:03:53

What's the difference (in use) between into-array and to-array? They look to me like they do the same thing with different implementations.

peeja15:03:57

Ah, it looks like into-array is for seqs, and to-array is for collections. Is that right?

dnolen16:03:03

@peeja: not quite, to-array appears to be bootstrapping Clojure-ism

dnolen16:03:13

I see no reason to use it over into-array

peeja16:03:35

Ah, that makes sense. Thanks.

niwinz16:03:35

(extend-type js/Rx.Subscription
  cljs.core/IFn
  (-invoke [this]
    (.unsubscribe this)))
I'm doing something evidently wrong but I don't see it 😞 This code raises Caused by: java.lang.UnsupportedOperationException: nth not supported on this type: Symbol exception

niwinz16:03:21

The same thing works as expected with reify and declaring it inside deftype.

dnolen16:03:19

niwinz: try to something simpler to ensure this isn’t a bug

dnolen16:03:25

js/String for example

niwinz16:03:57

@dnolen: the same, I have tried it already with js/String and js/Date

dnolen16:03:56

@niwinz: did you try dropping the ns bit, not needed

dnolen16:03:06

cljs.core/IFn -> IFn

niwinz16:03:08

yes, the same error

niwinz16:03:29

in fact is easy reproducible in node repl: (extend-type js/Date IFn (-invoke [_] 33))

niwinz16:03:13

nice, thanks!

george.w.singer16:03:25

Does anyone have any experience with figwheel name collisions between server and client files? I have a server build and a client build (with figwheel hooked up to the client build). Namewise, they both have the same entry point: name.core; however, this is purely nominal: the server files and the client files are completely separated via their cljs-build :source-paths fields (i.e., the server files are within src/cljs-server and the client files are within src/cljs-client. Nevertheless, when I try to connect figwheel the client, I get an error having to do with a server file! The only way I have figured out how to fix this is to rename the :main entry point on the client side to something different than the server side (i.e., I'm using name.core-client on the client side and name.core on the server side). How does figwheel have any knowledge of these server files?

dnolen16:03:58

@niwinz: at the moment appears to be a bug (a regression?) file an issue

martinklepsch16:03:25

@george.w.singer: if these two paths are on :source-paths their contents are next to each other on the classpath

niwinz16:03:25

@dnolen: ok, I'll do it asap

martinklepsch17:03:17

@george.w.singer: lets say you have src/cljs-server/name/core.cljs & src/cljs-client/name/core.cljs when adding src/cljs-server and src/cljs-client to :source-paths the files in them overlap relatively to their source-path root (both will be added at name/core.cljs)

george.w.singer17:03:08

Yes, but the client build and the server build have different :source-paths

:cljsbuild { :builds {
                         :cljs-server-none {
                           :source-paths ["src/cljs-server"]
                           :compiler { :optimizations :none
                                       :target        :nodejs
                                       :output-dir    "out/out-cljs-server-none"
                                       :output-to     "target/cljs-server-none.js"
                                       :verbose       true
                                       :main          name.core
                                       :pretty-print  true }}

                         :cljs-client-none {
                           :source-paths ["src/cljs-client"]
                           :figwheel true
                           :compiler { :optimizations :none
                                       :asset-path    "js/compiled/out-cljs-client-none"
                                       :output-dir    "resources/public/js/compiled/out-cljs-client-none" 
                                       :output-to     "resources/public/js/compiled/cljs-client-none.js"
                                       :source-map-timestamp true
                                       :verbose       true
                                       :main          name.core
                                       }}

george.w.singer17:03:24

So there shouldn't be a name collision, right?

niwinz17:03:01

@dnolen: is strangelly happens only with IFn, if I replace in the same example IFn with IDeref, the code compiles without problems

niwinz17:03:14

I'm filling the issue just now for that

martinklepsch17:03:50

@george.w.singer: these source-paths mean something like "put the contents of these directories on the classpath"

martinklepsch17:03:16

The classpath can be thought of as another directory (simplified)

george.w.singer17:03:08

So distinct source-paths in the project.clj are just an illlusion

george.w.singer17:03:20

They are still all being piled onto a single classpath

george.w.singer17:03:48

If so, that is deeply confusing

george.w.singer17:03:13

There could be all kinds of name collisions within a full-stack project

martinklepsch17:03:51

That's true and I agree that it's confusing

martinklepsch17:03:31

Potentially tools (Lein/Boot) should print a warning if theres a clash between the files in the provided source-paths

george.w.singer17:03:24

At least I understand where this error is coming from (thanks for your help). A _client.cljs naming convention on the client-side files will fix this issue in the short-run.

george.w.singer17:03:00

Or perhaps renaming to src/cljs-server/name_of_project/core.cljs and src/cljs-client/name_of_project-CLIENT/core.cljs

george.w.singer17:03:14

i.e., renaming the client folders

dnolen17:03:50

@niwinz: it’s not so strange, IFn is a special case

martinklepsch17:03:07

@george.w.singer: I'd suggest the following: src/name/server/core.cljs + src/name/client/core.cljs

martinklepsch17:03:45

@george.w.singer: but of course either approach will work simple_smile

george.w.singer17:03:41

@martinklepsch: so many folders! Is one answer generally more idiomatic here (i.e., yours)?

tony.kay18:03:33

I have an obvious dependency-related issue that I'm trying to track down. On certain builds I get " No reader function for tag object" during cljs analyzer when invoking the reader...any thoughts?

tony.kay18:03:45

e.g. what specific library is probably wrong

roberto18:03:40

navis/untangled-server seems to have a dependency on clojurescript.test

roberto18:03:08

maybe try excluding it, similar to what you did with secretary ?

bwstearns21:03:48

@martinklepsch: I got it almost working, sorry for the delayed reply, but it was super late where I am so I ended up grabbing some sleep haha. It's good in that now I have a new problem but I think it's still rooted in my misunderstanding of js/cljsjs dependencies. Either I get no errors and nothing happens or I end up with some variant of TypeError: Cannot read property 'call' of undefined

darwin21:03:02

Cannot read property 'call' of undefined is reported when you end up doing something like (some-fn arg1 arg2 …) and some-fn is bound to null during runtime

darwin21:03:28

you might try to use cljs-devtools with :sanity-hints enabled to see more context for such errors in your console logs: https://github.com/binaryage/cljs-devtools/releases/tag/v0.4.0

bwstearns21:03:41

That looks like it could potentially cut down on the amount of late night cursing I do.

darwin21:03:24

it should definitely cut your bills for antidepressants 😉

mathpunk22:03:19

So maybe I'm trying to learn too many things at once. But I would like to figure out how these things are interrelated:

mathpunk22:03:30

I have need to start writing node.

mathpunk22:03:37

I thought, hey, I'll try clojurescripting node.

mathpunk22:03:51

I've had a good experience using CIDER to write Clojure.

mathpunk22:03:52

And now I'm confused about what it means to use Figwheel with a Node REPL and what CIDER would connect to

mathpunk22:03:14

And I don't actually know what Figwheel does, I just saw it to cool things when I was trying out devcards.

mathpunk22:03:02

Maybe I don't have a question. I'm just imagining a graph of a Node Repl, a Cider process, whatever it is that Figwheel does, and my server.js code, and wondering about the directions and names of the arrows among those nodes (sense #2)

mathpunk22:03:48

Maybe I don't have a question. I'm just imagining a graph of a Node Repl, a Cider process, whatever it is that Figwheel does, and my server.js code, and wondering about the directions and names of the arrows among those nodes (sense #2)

base69822:03:03

I'm sure there is a way to do it, but the little clojurescript project I have is wired to just use the straight figwheel repl.

base69822:03:47

there is a way to connect cider to that I believe. @bhauman Probably knows.

mathpunk22:03:52

I just like being able to send forms in a source file to a repl to see if they do what I think they do.

base69822:03:30

yeah that's obviously optimal

mathpunk22:03:49

I haven't really ever developed with anyone so, all my dev environments are basically feral outsider art~

mathpunk22:03:42

I'm reading that over, and I'm amused by how much you have to know in order to get the kind of environment in which it would be great to learn the things that you need to know in order to

base69822:03:13

yeah, i learned first by doing the 4clojure problems with the straight repl

base69822:03:34

it was painful even with rlwrap

smw22:03:11

This really hit home to me… between midje tests and devcards, I like editing the source file with auto-refresh much more than I like the standard repl-based use case, I think.

smw22:03:29

I might be missing something, though.