Fork me on GitHub
#clojurescript
<
2022-05-03
>
roklenarcic09:05:29

A lot of stuff in browser produces a promise of a chan. How do you test these functions in unit test? I cannot blockingly take from a chan or something?

Carlo10:05:02

How would I use something like https://www.npmjs.com/package/@react-midi/hooks in reagent? I started with this import ["@react-midi/hooks" :as midi-hooks] but I'm unsure on how to call the useMIDI() function in a way that doesn't cause an error.

p-himik10:05:23

Step 1: Make sure that what you imported is what you expect to see and not undefined or something else Step 2: Consult https://github.com/reagent-project/reagent/blob/master/doc/ReactFeatures.md#hooks

😍 1
💯 1
Carlo10:05:59

Awesome, this works:

(defn example []
  (let [aaa (midi-hooks/useMIDI)]
    [:div
     (js/console.log aaa)]))

(defn home-page []
  [:div
   [:f> example]])
Thank you as always!

👍 1
lambduhhh17:05:34

Ever wondered the “best” way to interop with javascript? Should you use “dot special form” or goog.object ? Do you need to type hint when using dot notation? how does this relate to Advanced Compilation? Well turns out, there IS a correct answer to all of these questions! and you can find out why during tomorrow’s episode of http://www.theclouncil.com where we will be covering some clojurescript intricacies that you won’t want to miss! Join the channel #the-clouncil for the zoom link!

😍 1
💯 1
awesome 1
henryw37408:05:37

I have wondered this! and it is not documented afaik so I wrote up some stuff here: https://widdindustries.com/clojurescript-jsinterop/ and tl;dr my preferred interop style is the dot style (foo.bar.baz) but unfortunately that won't survive advanced compilation (open issue https://clojure.atlassian.net/browse/CLJS-3315) will be interesting to see what the clouncil has to say on this

🎉 1
Adam Kalisz19:05:12

A similar question was asked a few months ago. I want to embed some data, perhaps 1 or 2 MB, in an HTML page that is a basis for an SPA. What is the best? Meta with a content value with an EDN or transit+JSON string? Or perhaps a script tag? Or a data tag? Are there some limits or significant performance implications with either approach?

p-himik19:05:24

I'd go with a <script> tag with application/transit+json. Not EDN because it would be larger and slower to parse it.

👍 2
simongray19:05:20

Perhaps this is a good fit for shadow-cljs modules?

Carlo19:05:48

Why can I write both:

(js/console.log "hey")
(.log js/console "hey")
and
(.send um-one-output [0x91, 60, 0x7f])
but not
(um-one-output.send [0x91, 60, 0x7f])
(the latter examples have some objects defined by me, but I suspect is the same for all user defined objects?)

dvingo20:05:35

seems to work fine

(def x #js{"my_fn" (fn [a] (.log js/console "HI" a))})
(x.my-fn 200)

p-himik20:05:18

IIRC the last example breaks on optimized builds, something to do with externs inference. And it works properly with js/* stuff because that stuff already has externs.

p-himik20:05:03

I myself don't use a.b syntax at all unless it also has js/ in front of it. And even then, it's pretty much only js/console stuff that I sprinkle around during development.

Carlo20:05:05

Thanks guys, where is the fact that I can write js/console.log documented? I hope to find the caveats there

p-himik20:05:13

Here: http://cljs.github.io/api/syntax/dot But it's rather base-bones in this regard. I think there's an issue about the externs issue that I described.

🙌 1
💯 1
dvingo00:05:16

if you want to dive in, you can trace the calls from here: https://github.com/clojure/clojurescript/blob/40358fc4c53090676da82e3f4c52920003678902/src/main/clojure/cljs/analyzer.cljc#L3549 If i'm following correctly the analyzer will output a map with :op :host-call which is emitted here: https://github.com/clojure/clojurescript/blob/40358fc4c53090676da82e3f4c52920003678902/src/main/clojure/cljs/compiler.cljc#L1432 that analysis fn analyze-dot has some externs checks so maybe that's where the bug is that Eugene mentioned?

henryw37408:05:08

interop stuff doesnt have much official doc afaik. I wrote this https://widdindustries.com/clojurescript-jsinterop/ which mentions issue: https://clojure.atlassian.net/browse/CLJS-3315

henryw37408:05:52

this will be the subject of #the-clouncil later today apparently

henryw37408:05:13

thanks @U051V5LLP I added a comment to that issue with your info.

henryw37408:05:36

it's something I'd like to see addressed and may look at fixing it myself at some point

dvingo14:05:58

oh nice! thanks @U051B9FU1 Might drop in and ask Mike if he knows : )

zalky20:05:12

Hi all! So I'm currently working on a project that pulls sass, clj and cljs assets from the java classpath via a dependnecy jar. Specifically, the sass was being compiled via sass4clj/jsass/libass, but those are now deprecated, and jsass throws errors on an M1 mac. Seems like it's time to move on. Dart-sass is now the reference impl for sass, but I haven't seen a lot of examples on how to use it as part of a cljs build. Anyone have an pointers or resources? Ideally I'd like to be able to pull resources from a jar and compile them via the dart sass compiler.

p-himik20:05:35

> I haven't seen a lot of examples on how to use it as part of a cljs build Just use it as a separate tool. I ended up writing a CLJ script that I run with shadow-cljs run that shells out to sass.

p-himik20:05:57

That gives you flexibility where you can pull anything from anywhere since it's all driven by CLJ code.

juhoteperi20:05:48

You could also call sass from Shadow: https://shadow-cljs.github.io/docs/UsersGuide.html#_calling_watch_via_clj_run Something like

(let [cmd ["npx" "sass" "--watch" "-I" "../foobar/src/scss" "-I" "."
             "src/scss/:target/dev/public/css/"]
        process (-> (ProcessBuilder. ^"[Ljava.lang.String;" (into-array String cmd))
                    (.inheritIO))]
    (.start process))
But in this example sass process isn't killed if java process is killed, though it stops on ctrl-c. I have better version somewhere.

juhoteperi20:05:04

Doesn't help with requiring resources from classpath though. I've just copied the few lines of css I might have from some clj libs into the project. Mostly just using deps from npm.

zalky20:05:33

@U2FRKM4TW, @U061V0GG2, thanks very much, I am already using shadow in our build, so the approach you two recommend looks very promising. The shelling out was the missing piece, I think. I should be able to filter the classpath for sass resources/directories, and launch any watch tasks from there.

juhoteperi12:05:40

Here is a full Shadow watch with Dart Sass example: https://gist.github.com/Deraen/695c94848d3ee05990239d403f7fe733

👍 1