Fork me on GitHub
#clojurescript
<
2022-09-28
>
Jan Šuráň00:09:01

Hi, does anyone have any idea, why it might be not working? (Shadow-cljs won't compile)

thheller04:09:31

@suran.orgpad dependency conflict. make sure the closure-compiler version you are getting is the one the shadow-cljs version you use needs

Jan Šuráň09:09:17

I though it might be a dependency problem... I was using a version that came the first on the top of Google search when I was searching for the library and I thought it was the newest one. Thank you very much!

thheller16:09:30

you shouldn't need to add it to your dependencies at all. shadow-cljs already depends on it, so you'll get it anyways

M J08:09:13

Hello, I am using re-com checkbox, where the default is that clicking the label also checks the box. How do I prevent it, all I want is just clicking the checkbox itself to make the checkbox "checked or unchecked" This is how I defined it:

(defn checkbox-component [{:keys [name ticked? onChange attr]}]
  [checkbox
   :src       (at)
   :label     name
   :model     ticked?
   :class (checkbox-style)
   :on-change onChange
   :attr attr
   :style {:background-color "red"}])
And this is how I used it:
[checkbox/checkbox-component {:name [h-box
                                                                             :gap "6px"
                                                                             :children [name]]
                                                                      :ticked? ticked?
                                                                      :attr {:on-click #(.stopPropagation %)}
                                                                      :onChange #(reset! selected? true)}]

p-himik08:09:20

Not supported by the component itself. But you can use a checkbox without a label and just add a label to it via h-box.

M J10:09:49

Okay thanks a lot

👍 1
shaunlebron19:09:03

Does clojure and cljs interpret ^foo differently? It seems like clojure interprets it as ^{:tag <foo evaluated>} whereas cljs interprets it as ^{:tag <the symbol foo>}

shaunlebron20:09:01

oh, it depends on when it’s evaluated:

(def ^foo x {})  ;; <-- foo is not evaluated
(def x ^foo {})  ;; <-- foo is evaluated

shaunlebron20:09:16

oh, I think this means the metadata’s evaluation is contingent on the evaluation of the form itself. that makes sense

p-himik22:09:03

Why does it make sense? Especially given that it differs from Clojure.

shaunlebron22:09:49

Does the example differ between clj and cljs? I think i tried it in both repls and when foo was undefined, an error only occurred on the second line for both

shaunlebron22:09:57

I sent a related question on #cljs-dev with an example that does actually differ in implementation

p-himik22:09:07

ClojureScript 1.11.60
cljs.user=> (def ^a x [])
#'cljs.user/x
cljs.user=> (:tag (meta #'x))
a
Clojure 1.11.1
user=> (def ^a x [])
Syntax error compiling at (REPL:1:1).
Unable to resolve symbol: a in this context

shaunlebron22:09:40

Thanks that's a discrepancy

p-himik22:09:31

I guess that's due to the fact that vars in CLJS don't exist in the same way CLJ vars do. When you compile just (def ^a x 1) in CLJS, you won't even get that :tag a in the resulting JS. It simply won't be present at all. But if you also use #'x somewhere, that metadata will be there. But it will be - right where you used #' and not def. Of course, that metadata could include a instead of 'a, but perhaps it's done this way to not take the run time too far from the compile time since the value of a cannot be known at compile time.

👍 1
p-himik23:09:17

Right (from https://clojurescript.org/about/differences#_special_forms): > Vars are not reified at runtime. When the compiler encounters the var special form it emits a Var instance reflecting compile time metadata. (This satisfies many common static use cases.)

👍 1
thheller05:09:46

metadata on vars is not evaluated and only stored in the analyzer data on the compiler side as EDN

thheller05:09:59

only exception is :test which is actually handled be the compiler and evaluated

thheller05:09:09

(for cljs.test purposes)

thheller05:09:02

metadata on maps and stuff is actually evaluated becomes it becomes actual metadata on the thing in the runtime

shaunlebron18:09:50

finally caught up on this. this makes sense, thanks yall 👍

prnc21:09:23

In a sequence like the following

[:some/keyword #object[Object [object Object]] {} 1 2 ]
Is there a good way to delineate between js / cljs e.g. remove the js thing whatever it maybe and leave only cljs things? :)

phronmophobic21:09:13

they share the same runtime so the line between a js value and cljs value is fuzzy. I'm sure you could draw the line somewhere, but without knowing the context, it's difficult to offer a suggestion for how to draw the line.

shaunlebron21:09:32

(filter (some-fn object? array?) ...)

prnc07:09:16

> so the line between a js value and cljs value is fuzzy yes I was wondering if anyone has devised somewhat reliable test and if it’s possible at all the particular case I was looking at was that of a goog.events.BrowserEvent which fails object? , but there might be others

skylize22:09:05

BrowserEventitself is a function, which we can certainly test.

=> (js-fn? BrowserEvent)
true
I assume you mean an instance of a BrowserEvent, which can also be checked.
=> (let [event (BrowserEvent. (js/Event. "foo"))]
     (instance? BrowserEvent event))
true
For a general case, this little hack seems to get the job done (except for functions). Though, I'm guessing there are edge cases here I am totally unaware of.
=> (defn clj? [x]
     (boolean (re-find #"\bthis.cljs\$lang" (.toString (type x)))))
nil

=> (clj? {})
true

=> (clj? #js{})
false

=> (clj? (BrowserEvent. (js/Event. "foo")))
false

skylize22:09:09

There is really no useful line when it comes to functions. They all report the same type info. (Again, probably some edge case here I am oblivious to.)

=> (deftype Foo [])

=> (= (type (fn []))
      (type (.-stringify js/JSON))
      (type Foo)   ;; Foo is a constructor, aka function.
      (type BrowserEvent))   ;; Same for BrowserEvent.
      (type map)
true

(.toString (type (fn [])))
"function Function() { [native code] }"
You'll just need to decide whether to include or omit functions.
=> (defn clj? [x]
     (boolean (re-find #"\bthis.cljs\$lang" (.toString (type x)))))
nil 

=> (let [coll {:fn (fn foo [] :bar)
                :event (BrowserEvent. (js/Event. "foo"))
                :coll [1 2 3]}]
      (into {} (filter
                (comp #(or (clj? %) (js-fn? %)) val)
                coll)))
{:fn #object[my$namespace$foo],
 :coll [1 2 3]}

prnc15:10:49

> There is really no useful line when it comes to functions Yes functions is where I gave up 🙂 > For a general case, this little hack seems to get the job done Ha! that is a great little hack indeed! Thanks writing this up, very helpful 🙏

😊 1