Fork me on GitHub
#clojurescript
<
2022-05-09
>
eploko00:05:37

One can log to the console in two ways: 1. (js/console.log "blah") 2. (.log js/console "blah") Which one would be the most preferred/idiomatic and why?

p-himik04:05:09

I'd say that at this point it's a matter of preference.

ivana07:05:21

(prn "blah") is my choice 🙂

p-himik08:05:05

Which works well only for scalars. :) As soon as it's an object of any kind, js/console.log is much better, especially if you have cljs-devtools installed.

Chris McCormick10:05:14

for those of us using Firefox:

(defn log [& args] (apply js/console.log (clj->js args)) (first args))

p-himik11:05:49

But also, even without that, using stuff like Portal would probably be better than clj->js.

Chris McCormick11:05:00

Ah that's excellent they are funding that! Thanks for the heads-up about Portal.

genRaiy13:05:35

I'm using p/let from promesa and generally having a lot of success. But I'm finding it tricky to avoid promise complaints when I call functions inside the p/let that also have p/let inside. For example when I want to fetch data and then map over it with bunch of fetches per item. Is there an established pattern for this?

genRaiy13:05:48

(p/let [xs (fetch-xs)
        xs+ (map more-fetching xs)]
...

p-himik13:05:44

> promise complaints What are those?

genRaiy13:05:53

I either get that the promise is not ISqeable or a list of promises

genRaiy13:05:23

payments (fetch-pending-payments api options)
          with-linked (map (fn [payment]
                             (let [data (account-data api (get-in payment [:details :sourceAccountId]))]
                                    (merge payment data)))
                           payments)]

genRaiy13:05:26

both fetch-pending-payments and account-data follow the same pattern

genRaiy13:05:22

(p/let [url (js/URL. (str api-url "something"))
           params (js/URLSearchParams. (clj->js search-conditions))
           _ (j/assoc! url :search params)]
          (p/-> (fetch url))
                (.json)
                (.-content)
                (js->clj :keywordize-keys true)))

genRaiy13:05:42

there is some small variations on let bindings and the p/-> pipelines between the functions but it's the same pattern ...

genRaiy13:05:41

the payments binding resolves but the with-linked comes back with a list of Promise objects

Chris McCormick13:05:00

sorry i mis-hit enter facepalm

genRaiy13:05:10

relateable

Chris McCormick13:05:48

if you are returning a seq of promises you probably want to use p/all to wait for all of them.

🎉 1
genRaiy13:05:11

ah, ok - I'll give that a shot

genRaiy13:05:37

ok, combination of p/all and p/let did the trick - thanks @UUSQUGUF3

metal 1
Chris McCormick13:05:10

oh great, glad you got it working.

1
mozinator214:05:01

hi guys, I created the channel #remix for having discussions about integrating clojurescript with remix.run

p-himik17:05:06

Is ^js ever necessary with this-as? I.e. in code like this:

(this-as this
  (.doStuff ^js this))

thheller17:05:20

depends on what this is

p-himik17:05:25

Assuming it's a object from some NPM library.

danieroux17:05:25

This feels like a Javascript joke, waiting for the punchline. I know it's not, and still feels like it 😊

🙂 1
kennytilton12:05:29

Am I the only one who thought it was a Bill Clinton callback? :thinking_face: