Fork me on GitHub
#clojurescript
<
2017-12-14
>
blake00:12:04

Hey, all. Trying to work out the conversion of this JS to CLJS: $(function() $("#datepicker").datepicker();});

blake00:12:23

I've gotten pretty close but can't seem to get the wrapping $(function()...) part.

blake00:12:32

I have: (js/$ (fn [] (-> (js/$ ".datepicker") (.datepicker))))

blake00:12:29

Which results in: return function() {return $(".datepicker").datepicker();};

blake00:12:39

So I don't know what's happening to the outer js/$.

alexisvincent00:12:44

Has anyone managed to get React Router to work via NPM imports?

vemv00:12:41

@blake.watson code seems correct, except for the #-`.` swap. could it be simply that?

blake00:12:09

@vemv Oh, I'm switching between ID and class selectors, is all. I want $(function() $(".datepicker").datepicker();});

blake00:12:58

I don't think it's working. I've got two problems whenever I do something like this: I don't know if I have the js->cljs transliteration right, and I don't know if it's actually being called, or called at the right time.

vemv00:12:56

trying out things at the repl can help

vemv00:12:06

that way you don't depend so much on timing

vemv00:12:26

i.e you remove need for $(function()) wrapping

blake00:12:01

Do you? Like, I can put that js into the console after the page has rendered and it will work.

vemv00:12:36

I mean, just for the purpose of figuring out things you can:

vemv00:12:47

load the page, without this cljs code

vemv00:12:54

interact w/ page via repl

blake00:12:56

Ooh. My CLJS tab is working all of a sudden.

blake00:12:20

Wait, so the code DOES work. Cool. It's just a matter of figuring out where it should go, then.

blake00:12:29

So I have a react app, and it's building a screen from data with all the controls. I have it at the bottom of the render- function but that's not right, I guess.

vemv00:12:55

A React-created element that responds to the $(".datepicker") selector can exist/disappear as things are re-rendered

vemv00:12:05

i.e. through the 'component lifecycle'

vemv00:12:14

that could be biting you

blake00:12:24

Right, that's always been my confusion.

souenzzo00:12:51

I'm trying to use a npm dep in my project and getting:

(fig-start)
Figwheel: Starting server at 
Figwheel: Watching build - dev
Figwheel: Cleaning build - dev
Compiling "resources/public/js/app.js" from ["src" "dev"]...
Failed to compile "resources/public/js/app.js" in 32.571 seconds.
----  Exception    ----
  Assert failed: cljs.analyzer/foreign-dep? expected symbol got "graphql-voyager"
(symbol? dep)
----  Exception Stack Trace  ----
I'm requiring ["graphql-voyager" :refer [Voyager]] and using :npm-deps {:graphql-voyager "1.0.0-rc.10"} :install-deps true on :compiler profile.

noisesmith00:12:11

is there a clojurescript doc that describes why people keep using strings in require blocks?

noisesmith00:12:21

I mean, that never looked right to me

alexisvincent00:12:33

@noisesmith Its in one of the guides

noisesmith00:12:00

but if cljs is complaining maybe you need a newer version?

alexisvincent00:12:01

its to support requires like tis “sdfsdfsdf/sdfsdfsdf”

souenzzo00:12:27

I just used the "raw" cljs.build.api and get no erros. I think that it's a #figwheel problem

noisesmith00:12:44

do you have the latest figwheel?

souenzzo00:12:45

yep, "0.5.14"

bhauman20:12:13

you can't use quoted args in a leinigen profile.clj

souenzzo12:12:00

My figwheel/lein setup works. I'm in trouble just with this tutorial https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules then I try to (require '["a-Npm-like-name" :as clj-name])

alexisvincent00:12:52

Yeah… but Im still getting errors. I cant import React Router. Keep getting errors

alexisvincent00:12:05

maybe not latest

noisesmith00:12:19

@alexisvincent you could also check out lein with-profile cljsbuild deps :tree and look at conflicts

noisesmith00:12:35

or lein with-profile figwheel deps :tree etc.

noisesmith00:12:27

issues log in figwheel clearly shows someone requested this in a feature request issue, and the issue was closed marking as implemented

noisesmith00:12:45

as of late june

alexisvincent00:12:33

hmm thanks. Thats helpful

alexisvincent00:12:05

It looks like it was an error with rum. Since React Router assumes a react instance and rum includes its own one

alexisvincent00:12:12

got a little bit further

noisesmith00:12:22

ahh that sounds like something that could cause that issue

alexisvincent00:12:27

but hit something else now

featheredtoast02:12:45

Hey friends, I'm investigating compiling clojurescript with macros - is it possible to define a macro that exports a function to js-land via ^:export metadata in a macro? Best I have for it right now is (defn (with-meta ~(symbol fn-name) :export) [] ...) since I hear reader macros are no good in macros.

featheredtoast02:12:36

nm sorry, I clearly didn't read defn specs closely enough - for anyone else wondering, (defn ~(symbol fn-name) {:export true} [] ...) did the trick just fine.

helios08:12:48

question guys: what is your choice of charts library to work with a frontend in reagent ?

Roman Liutikov13:12:00

recharts is pretty good React lib built on top of d3 http://recharts.org/#/en-US/

scknkkrer13:12:32

Guys, How is that possible with production build with npm modules ? I can use it with dev profile, Clojurescript can find this module and add for me. But it comes to production build. It can’t.

scknkkrer13:12:58

It is obvious too ?

danielbraun15:12:16

@scknkkrer you're probably missing externs

scknkkrer15:12:01

Nope, cljsbuild npm-deps feature only works with optimization is none profile.

scknkkrer15:12:21

But thanks for asking @dabra.

danielbraun15:12:55

oh, yeah you need to add :npm-deps to all builds

scknkkrer15:12:07

Yeah, my problem was, I just want to get optimized out from project. When I build min version of my project it gives error because npm-deps feature doesn’t work with advanced optimization profile option.

scknkkrer15:12:11

It’s a good trick.

alexisvincent15:12:30

Does anyone know how to use normal React components nicely in rum. Without resorting to react/createElement nonsense

derpocious16:12:30

Hey, does anyone know why cljs has put! but doesn't have take!?

derpocious16:12:30

@the-kenny thanks, do you know why this prints for <! but not for take!?

the-kenny16:12:31

derpocious: check the documentation for take!. In Javascript world you can't do blocking stuff at all, so you need to supply a function take! will call when a value arrives on the channel

derpocious16:12:44

thanks. this might be dumb question, but is there documentation for cljs core.async?

derpocious16:12:51

besides the source itself

derpocious16:12:45

Also, in the source for <! all it does is throw an error? that doesn't seem right

derpocious16:12:51

(defn <!
  "takes a val from port. Must be called inside a (go ...) block. Will
  return nil if closed. Will park if nothing is available.
  Returns true unless port is already closed"
  [port]
  (throw (js/Error. "<! used not in (go ...) block")))

lopalghost16:12:52

@derpocious the go macro rewrites the code inside (<! ...)

lopalghost16:12:03

the function body is only there for if you call it outside of a go block

derpocious16:12:09

ah ok thanks

derpocious16:12:22

is there a difference between "port" and "channel"?

chris16:12:37

the source for the cljs version of core.async is wildly complicated

chris16:12:57

the go macro is probably the most complicated macro I've ever seen

noisesmith17:12:49

@derpocious a channel implements WritePort and ReadPort

bhauman20:12:25

@souenzzo just in case you haven't figured this out, the answer to your problem is that you can't used quoted symbols in a leinigen profile

bhauman20:12:40

just take the quotes off and you will be all set

mfikes20:12:08

@derpocious Your code should instead look like

(go
   (>! a-channel "Hello, wworld!"))

(take! a-channel println)

hagmonk21:12:43

hey @mfikes ... I was just trying to understand a post you made a few years back: <https://groups.google.com/forum/#!topic/clojure/34luqPyg6L4>

hagmonk21:12:35

I'm trying to export a lib from CLJS to JS and require the JS side to see "normal" looking functions

hagmonk21:12:11

it sounded like this was what you wanted too, but perhaps I misread.

mfikes21:12:30

(As an aside, FWIW, the ^:export stuff on protocols is now mentioned officially at https://clojurescript.org/reference/advanced-compilation#access-from-javascript)

mfikes21:12:28

Yes, @hagmonk if you use ^:export, this makes it possible for JavaScript to make calls into your code when :advanced is applied.

hagmonk21:12:55

I'm using optimization: whitespace right now for a couple of reasons, but on the JS side even with ^:export I still see myns$module$IDatasource$testDataSource$arity$1()

hagmonk21:12:17

rather than myns.module.testDataSource

mfikes21:12:41

Well, ^:export doesn't change your code. It only adds additional aliases that point into your optimized code. But it is interesting that you are running into this under :whitespace because in that case ^:export is not needed at all. Your functions should be available in unaltered form.

thheller21:12:05

@hagmonk thats how protocols looks. if you want actual JS functions you need to define the functions on Object

hagmonk21:12:10

ah, I think I'm misunderstanding what :export is supposed to provide ... really it's just "don't munge"?

thheller21:12:38

(deftype Thing [] Object (^:export foo [this] ....))

mfikes21:12:10

@hagmonk I need to run. But that Google groups post describes stuff that is open source. You can take a look for yourself how I did it: https://github.com/mfikes/goby

hagmonk21:12:36

Cool, I'll pick this up again later, I also have to run. thanks @mfikes and @thheller!

mfikes21:12:44

@hagmonk FWIW, if you define the example protocol on the ClojureScript site:

(defprotocol IFoo
  (^:export bar [this])
  (baz [this x])
  (^:export quux [this x y]))
Then (js* "cljs.user.bar") "exists"

mfikes21:12:37

@hagmonk Furthermore:

cljs.user=> (defrecord Foo [] IFoo (bar [this] 1))
cljs.user/Foo
cljs.user=> (def f (->Foo))
#'cljs.user/f
cljs.user=> (js* "cljs.user.bar(cljs.user.f)")
1

thheller21:12:40

@mfikes myns$module$IDatasource$testDataSource$arity$1() is the property on the actual object, not the dispatch fn. so I think he was looking to export a propery that external JS can call.

thheller22:12:09

ie. f.bar() which doesn’t exist since its a protocol not a normal fn

mfikes22:12:24

@thheller Could be. @hagmonk initially referred to a question I had asked and then answered, and that question was about exporting functions defined by protocols.

thheller22:12:15

yep, I think its just a misunderstanding regarding how protocols work

mfikes22:12:16

IMHO @hagmonk will have to clarify the question

mfikes22:12:59

(Honestly, my difficulty with these kinds of questions is that I don't know JS.)

mfikes22:12:13

I think you are right, though @thheller in that @hagmonk referred to "normal" looking functions.

thheller22:12:16

I know that he is looking to implement a grafana plugin which expects JS classes so I assumed so.