Fork me on GitHub
#clojurescript
<
2022-04-06
>
Adir Ohayon12:04:51

Hello everyone! (newbie here, be gentle 🥸) Anyone knows a way to pretty-print a map? https://clojuredocs.org/clojure.pprint/write function prints it beautifully on my console but I want it to be printed on my web page.

thheller12:04:58

[:pre (with-out-str (pprint {:a 1}))] with (:require [clojure.pprint :refer (pprint)])

Ivan Fedorov14:04:31

what’s the current META for clojurescript testing with shadow? the good old CI build targeting Karma?

thheller14:04:33

if you need browser testing then karma, otherwise just :node-test is fine

❤️ 1
Mno17:04:53

Can I get some recommendations for how to do HTTP Requests in node cljs?

djblue17:04:09

I usually use something like:

(defn fetch [url options]
  (let [https? (str/starts-with? url "https")
        http   (js/require (str "http" (when https? "s")))]
    (js/Promise.
     (fn [resolve reject]
       (let [req (.request
                  http
                  url
                  (clj->js options)
                  (fn [res]
                    (let [body (atom "")]
                      (.on res "data" #(swap! body str %))
                      (.on res "error" reject)
                      (.on res "end" #(resolve @body)))))]
         (.write req (:body options))
         (.end req))))))

Mno17:04:42

oh wow this is definitely going to save me a lot of failing to interop

💯 1
djblue18:04:46

Might need to include [clojure.string :as str] in your requires

Mno20:04:27

Well.. I get back a promise and I'm unsure what to do with it. 😅 so I guess I'm learning about that now.

djblue20:04:14

You can (.then promise (fn [value] ...)). Everything dealing with IO in node is going to involve callbacks or promises

lilactown20:04:51

i think i saw that the latest version of node comes with js/fetch

💯 1
Mno17:04:47

Libraries, or maybe something built in both work, anything I google comes up with cljs-http, but it seemed a little convoluted for a simple github action that I'm making.

Jason19:04:33

Does anyone know what’s best practice for doing css animations in clojurescript? I don’t want to have to hand roll the css keyframe and swap classes and I like to keep everything inline so animations are internal to a component. Any ideas?

jrychter07:04:13

I just use animate.css for all the simple transitions/animations, but I'm not sure if that is all you need. https://animate.style

Jason17:04:10

Hadn’t seen this but yeah think I’m going to need something more powerful/I’m a control freak. Good to know there’s stuff out there for something like this though. My current approach is just to hand roll the css animations so if that’s what I stick with at least this would be a good reference

Jason19:04:42

Cljss looks promising

Jason19:04:06

Not sure how mature it is though as I’m still very new to clojurescript