Fork me on GitHub
#clojurescript
<
2019-06-01
>
Filipe Silva11:06:23

Heya, apologies if this is a silly question, but how does issue reporting work for ClojureScript? https://clojurescript.org/community/reporting-issues says that issues should be reported on http://dev.clojure.org/jira/browse/CLJS But it doesn't seem possible to comment or create issues there without an account. If an account is needed, how does one go about obtaining it?

gklijs12:06:40

I think you can ask for an account. #cljs-dev could help you further.

Filipe Silva12:06:52

thank you for the direction, I will ask there.

hendore15:06:50

Sorry if this is really obvious but I’m left wondering why there is two ways to call a javascript function from cljs

hendore15:06:56

(def btn (.getElementById js/document "my-btn"))
(def btn (js/document.getElementById "my-btn"))

hendore15:06:22

I see the first one more from what I’ve read but have come across the second once or twice

lilactown15:06:21

there are a number of ways to call a method on an object. between the two, (.getElementById js/document "my-btn") is “more correct”

lilactown15:06:58

js/document.getElementById isn’t part of the spec, but was an undocumented thing that many people used and so we can’t ever remove

hendore15:06:06

@lilactown roger that, thanks for the heads up :thumbsup:

lilactown15:06:43

sure thing. another one you might run into is: (. js/document getElementById "my-btn") it does the same thing, it’s just sometimes easier to read. you can read about the whole gamut here: https://www.verypossible.com/blog/clojurescript-and-javascript-interoperability-a-comprehensive-guide

hendore15:06:32

That was an interesting read, so the first version I posted is actually just syntactic sugar for the dot special form, I’m not quite up to speed with macros yet but after expanding a couple I can see what’s happening just can’t think how it works 🙂

cljs.user=> (macroexpand '(.x))
(. nil x)
cljs.user=> (macroexpand '(.))
(.)
cljs.user=> (macroexpand '(.x blah))
(. blah x)
cljs.user=> (macroexpand '(.x blah a b c))
(. blah x a b c)

hendore15:06:08

Still, very good to know what my code is expanding to before compilation 🙂

hendore15:06:09

Also, I didn’t realise you could name a function . until looking at this

hendore15:06:29

Scratch that, maybe you can’t

user=> (defn . [name] (println (str "Hello, " name)))
#'user/.
user=> (. "foobar")
Syntax error (IllegalArgumentException) compiling . at (REPL:1:1).
Malformed member expression, expecting (. target member ...)
now I’m confused 😄

souenzzo23:06:30

Clojure syntax (op arg1 arg2) Where op can be: - A special form, like if, def and . - A macro - A object Clojure you check in this order, so . function will not work. But you can call (apply .) and . function will be called

dominicm20:06:50

I'm a bit confused, hoping for a sanity check :). I am doing a defmethod against a multi, and then doing (prn (keys (methods reader))). But my :default is later getting triggered for that method, and when I do (prn (keys (methods reader))) I can't see the method any more.

dominicm22:06:31

This seems to have been caused (according to bisect) by moving some code from .core into a .alpha.core and then referring them in .core

dominicm22:06:29

I don't really understand how that's caused this bug though 😟

dominicm22:06:10

Figured it out (mostly!) I have a different multi-method calling that multi-method, and when it does (update expansion ::value #(reader opts (:tag tl) %)) where reader is the broken multi-method, that doesn't contain the custom reader. But if I re-evaluate the first multi-method from the REPL, that fixes it.

dominicm22:06:29

It's as if when the defmethod is run, the reference to reader is snapshot?

dominicm22:06:41

Aha! The problem is that it's a cljc file! There's two versions of reader, one in core$macros, and one in core. How do I fix this? 😟

dominicm08:06:33

This is an open source project so I can share the failing commit, but I've solved this for now by inlining macrovich into my project. I'd be happy to help someone repro, but I don't understand the environment well enough to progress a repro.

thheller20:06:05

@dominicm depends on what you dispatch the multi on. say you use type with a defrecord and re-declare that record

dominicm20:06:21

@thheller It's the :tag from a tagged-literal, so a symbol, always.

dominicm21:06:02

okay, even weirder. If I catch the exception from the :default and ignore it, then following that do (methods), I get a different result...

dominicm21:06:49

Feels like there's 2 readers, somehow 😟

yuhan21:06:26

did you interactively redefine the defmulti form perhaps?

dominicm21:06:44

@qythium Nope. This is a cold run in lumo (nodejs). I've double checked for a double defmulti, just in case.

dominicm21:06:40

in fact, the metadata points at the exact right place.

dominicm21:06:43

right, looks like it's only broken locally. CI passes. well /shrug

hendore21:06:05

Does this project need both project.clj and deps.edn https://github.com/bhauman/flappy-bird-demo-new or does the author just provide both so that it can be launched from different tools?

dominicm21:06:19

@matt.henley both so that it can be launched from different tools

hendore21:06:38

Thanks, I was just wondering why dependencies where being declared in two places. Is this common in a lot of clojurescript projects or just opensource demos/examples?

dominicm21:06:31

I have mostly seen this in bhauman's projects :)

hendore21:06:51

Cool, I’m able to watch and compile changes using clojure cli tools so my current workflow is change code, save, refresh page (baby steps), I’ve now added figwheel as a dependency to deps.edn and instead of using running clj -m cljs.main ... I’m using clj -m figwheel.main ... so that removes the need to manually refresh (which is awesome) but I’m really struggling to connect to the repl from emacs (I can get it working fine for clj just not cljs)

dominicm22:06:10

Figured it out (mostly!) I have a different multi-method calling that multi-method, and when it does (update expansion ::value #(reader opts (:tag tl) %)) where reader is the broken multi-method, that doesn't contain the custom reader. But if I re-evaluate the first multi-method from the REPL, that fixes it.

souenzzo23:06:30

Clojure syntax (op arg1 arg2) Where op can be: - A special form, like if, def and . - A macro - A object Clojure you check in this order, so . function will not work. But you can call (apply .) and . function will be called

dominicm08:06:33

This is an open source project so I can share the failing commit, but I've solved this for now by inlining macrovich into my project. I'd be happy to help someone repro, but I don't understand the environment well enough to progress a repro.