Fork me on GitHub
#clojurescript
<
2016-08-18
>
Jon07:08:08

(defn f [x y])

(def some-map {:g f})

(def args [1 2])

; this line of code is in a library...
(apply (:g some-map) args)
; is it possible to it check args number before running?

crankyadmin10:08:08

Hi, I'm attempting to use recharts with reagent. In my home.html I have {% script "/js/Recharts.js" %} but when I try and call it I get exceptions back

Recharts.js:968 Uncaught TypeError: Cannot read property 'PropTypes' of undefinedmodule.exports @ Recharts.js:968__webpack_require__ @ Recharts.js:30testObject @ Recharts.js:99__webpack_require__ @ Recharts.js:30Object.defineProperty.value @ Recharts.js:80__webpack_require__ @ Recharts.js:30(anonymous function) @ Recharts.js:50(anonymous function) @ Recharts.js:53webpackUniversalModuleDefinition @ Recharts.js:9(anonymous function) @ Recharts.js:10
ui_recharts_wrapper.cljs:5 Uncaught TypeError: Cannot read property 'PieChart' of undefined(anonymous function) @ ui_recharts_wrapper.cljs:5
and ui_recharts_wrapper.cljs:5 Uncaught TypeError: Cannot read property 'PieChart' of undefined

crankyadmin10:08:13

My source looks like (def PieChart (r/adapt-react-class js/window.Recharts.PieChart.))

crankyadmin10:08:57

Doesn't seem to matter to much where I try and import in my code (moving it around lines), but interestingly it -sometimes- works.

crankyadmin10:08:18

(well figwheel makes it work)

crankyadmin10:08:40

Which tends to suggest to me its being called before everything is ready. What am I missing here?

crankyadmin10:08:03

(defn make-pie-chart
  ""
  [{:keys [width height data]}]
  (let [PieChart (r/adapt-react-class js/window.Recharts.PieChart.)
        Pie (r/adapt-react-class js/window.Recharts.Pie.)
        ToolTip (r/adapt-react-class js/window.Recharts.Tooltip.)
        Cell (r/adapt-react-class js/window.Recharts.Cell.)]
    [PieChart {:width width
               :height height}
     [{:fill "#82ca9d"
       :data data
       :inner-radius 80}
      [Cell {:key 1 :fill red-color}]
      [Cell {:key 2 :fill green-color}]
      [Cell {:key 3 :fill blue-color}]]
     [ToolTip]])

  )

crankyadmin10:08:50

Need to be called like that. The defs where being evaluated on load... which wasn't what I wanted... I should have known better... ha well...

sandbags11:08:35

Not quite sure what to even search for on this. I just moved a data structure out of my code into a .edn file that I am loading at run-time using cljs-http library. At this point it starts failing the specs. What appears to be the issue is that my namespace qualified keywords, when loaded remotely, don’t get namespace qualified but stay as “::value"

sandbags11:08:13

cljs-http is handling conversion of the HTTP response body from EDN into clojure data structures

sandbags11:08:35

i’m actually a little suprised they don’t get qualified into, e.g., the cljs-http.client namespace

joost-diepenmaat11:08:14

I don’t think ::double-colon-keywords are valid EDN

sandbags11:08:04

i mean now i think about it, it’s ambiguous

sandbags11:08:11

outside of the context of a namespace

joost-diepenmaat11:08:22

if you want a qualified keyword, you should probably just write out the full namespace. :foo.bar/keyword

sandbags11:08:34

well i was qualifying because this appeared to be the "right thing to do"

sandbags11:08:50

within the context of my source

sandbags11:08:11

however in the context of a separate data file I think I will just switch back to unqualified and switch my specs

joost-diepenmaat11:08:42

there’s a related issue in clojure that ::some-alias/foo is only valid when some-alias already refers to a namespace. meaning you cannot read clojure source code that contains those aliases unless the alias is set up in the current namespace.

joost-diepenmaat11:08:34

::" is not really qualifying anything. that’s just a shorthand for “keyword qualified with whatever the current namespace is” which makes little sense in a data file

sandbags11:08:23

Yes. As soon as you pointed it out I realised the meaninglessness of what I was doing.

fenton15:08:48

I've got a *.cljc library that I include in my cljs project. The *.cljc library has a namespace form like:

anmonteiro15:08:19

@fenton: in clojurescript, you have to require cljs.spec.impl.gen

fenton15:08:36

require that?

anmonteiro15:08:55

clojure.spec.impl.gen will also work, the point I’m trying to make is the impl part there

fenton15:08:14

ok, put that in my cljc library?

anmonteiro15:08:14

require that instead of clojure.spec.gen

anmonteiro15:08:23

for the CLJS branch

mfikes15:08:52

(There already is a var named cljs.spec/gen that would otherwise collide, given the way namespaces and vars are implemented in the generated JavaScript.)

fenton15:08:55

ah so i use this library for *.clj projects too, so I should resort to reader conditionals in this case.

mfikes15:08:06

@fenton Yes. (Perhaps you can even avoid directly using that namespace.)

fenton15:08:31

@mfikes, ok...i'll look into that...thanks all! 🙂

shaunlebron17:08:04

@fenton: @anmonteiro: I’m trying to get clojure.spec.gen to alias cljs.spec.impl.gen for this reason

shaunlebron17:08:29

David said: > I'd rather wait to see if people actually use this namespace frequently enough for this to be desirable.

shaunlebron17:08:41

so voice your opinion there if you want the alias

fenton17:08:26

@shaunlebron turned out i only had it in my namespace to help with REPL testing...so i could safely delete it as mike suggested...what do you use it for?

shaunlebron17:08:51

I haven’t used spec at all

shaunlebron17:08:02

just advocating for consistency when including clojure namespaces

shaunlebron17:08:59

(i’m the owner of the api docs, and would like it to stay sane)

anmonteiro17:08:40

@shaunlebron I don’t know if I’m in favor of that alias

anmonteiro17:08:02

so I haven’t expressed my opinion because of that

anmonteiro17:08:09

I haven’t needed that namespace yet

fenton17:08:14

ok. my mild opinion is that this is a bit less important than the namespace: [clojure.spec :as s], which aliases okay...

anmonteiro17:08:21

also, introducing a special case like that in the compiler opens a precendent for others that may come 🙂

fenton17:08:40

its not helpful in my use case, which i think is a common use case, and I'd be curious to find out if anyone does use it, and why...thats why i asked... i guess we'll see if anyone has a specific need for it.

shaunlebron17:08:33

i mean, practically, it doesn’t really matter if people don’t use it that much

shaunlebron17:08:44

i haven’t worked in the compiler, so I’m not qualified to have an opinion on how it affects the compiler’s management

shaunlebron17:08:22

i’m only speaking from the API perspective

shaunlebron17:08:13

so, in regards to the API, it seems fine to make the compiler map clojure.* to the appropriate cljs.* namespaces, rather than offloading that responsibility to the user

fenton17:08:06

I guess to make a decision on it @anmonteiro and @dnolen also take into consideration the impact on the compiler code and weigh that against the API perspective. Unless there is more of a case for the uniformity with respect for this namespace, I guess, its not a clear decision to make the compiler mod, and if people want this mod, then maybe more of a case than just uniformity needs to be made... I'm guessing here, thats just my read.

shaunlebron17:08:53

i wonder if moving away from the general method of replacing clojure. with cljs. to see if the namespace resolves is a good idea

shaunlebron17:08:54

wouldn’t explicitly mapping the clojure.* => cljs.* namespaces be better to prevent weird cases like clojure.spec.impl.gen from resolving?

shaunlebron18:08:48

that way, we could replace the general rule + special case, with a finite set of explicit cases

shaunlebron18:08:10

and we wouldn’t have to set a precedent for special cases

fenton18:08:41

the con with that approach is that it could be more brittle in the sense if a new scenario comes up, may not need to touch the compiler as the general case takes care of it... but I dont have a current issue with the way it is for my selfish reasons, lol 😉

shaunlebron18:08:24

the problem is that the general case doesn’t work all the time, and it will continue breaking for other future impl namespaces. namespace additions in clojure are major version events, and can be added to an explicit namespace map as slowly as they come

fenton18:08:53

@shaunlebron IMO your points are valid. Think the discussion has laid out the pertinent issues... now I guess a higher authority will decide! 🙂

shaunlebron18:08:25

yeah! and sorry for the bike-shedding 🚲 (I seem to have strong feelings about api)

fenton18:08:41

@shaunlebron and I like trials biking! Good to have passions! lol 😉

shaunlebron18:08:56

(and now we’re both gushing about our bike hobbies in DM)

dnolen18:08:59

aliasing namespaces people aren’t using just isn’t a priority

dnolen18:08:07

no decision is going to be made until we get a lot more feedback

dnolen18:08:25

from users actively using clojure.spec

dnolen18:08:49

so it’s not a yes/no thing - let’s just wait and see

shaunlebron18:08:38

right on 👍

talexxx20:08:32

So if you make a utility you like in CLJS, how do you publish it?

shaunlebron20:08:23

@talexxx: are you using lein or boot?

talexxx20:08:44

Boot. I see there’s a section for that in that article, I’ll try it. Thanks

talexxx20:08:27

boot build-jar push-snapshot                                                   ~/g/hallo-color
Writing pom.xml and pom.properties...
Writing hallo-color-1.0.0.jar...
Installing hallo-color-1.0.0.jar...
CLOJARS_USER and CLOJARS_PASS were not set; please enter your Clojars credentials.
Username: talexxx
Password:
             clojure.lang.ExceptionInfo: java.lang.Exception: missing jar file or repo not found
    data: {:file
           "/var/folders/fq/_rst8fw93jl0dqjsc3vhqzrh0000gn/T/boot.user7039555530317153355.clj",
           :line 33}
java.util.concurrent.ExecutionException: java.lang.Exception: missing jar file or repo not found
                    java.lang.Exception: missing jar file or repo not found
     boot.task.built-in/fn/fn/fn/fn   built_in.clj:  768
  adzerk.bootlaces/eval802/fn/fn/fn  bootlaces.clj:   54
  adzerk.bootlaces/eval841/fn/fn/fn  bootlaces.clj:   62
     boot.task.built-in/fn/fn/fn/fn   built_in.clj:  716
     boot.task.built-in/fn/fn/fn/fn   built_in.clj:  618
     boot.task.built-in/fn/fn/fn/fn   built_in.clj:  342
                boot.core/run-tasks       core.clj:  794
                  boot.core/boot/fn       core.clj:  804
clojure.core/binding-conveyor-fn/fn       core.clj: 1916
                                …

shaunlebron20:08:54

@talexxx: looks like you found an issue => #C053K90BR. (I’ve never published with boot)

talexxx20:08:26

I’ll make a ticket in the boot repo.

jasonjckn22:08:43

does the leiningen checkouts feature work with clojurescript? if not how do I do multiple projects?

dnolen22:08:31

@jasonjckn I don’t see any reason it shouldn’t work

jasonjckn22:08:26

i put a syntax error into ./checkouts/mydep/src/...cljs. and it didn't notice it during lein cljsbuild

jasonjckn22:08:45

i'm now trying modifying my :source-paths to include ./checkouts/mydep/src

jasonjckn22:08:58

having more luck

dnolen22:08:20

@jasonjckn right lein isn’t going to look at :cljsbuild

dnolen22:08:29

so you need to dupe the source path stuff