Fork me on GitHub
#clojurescript
<
2021-09-09
>
dnolen13:09:08

that is the only way - and all ClojureScript types are mapped directly to JavaScript types - so it shouldn't be that tricky

dnolen14:09:06

all serious profiling of ClojureScript and it's libraries was done w/ Chrome Dev Tools - they are adequate IMO

Otto Nascarella20:09:18

question about async and with-redefs in clojurescript: is it possible to use both?

Otto Nascarella20:09:33

(def a 1)
(def b 2)

(deftest testing-async
  (testing "async testing"
    (with-redefs [a 5 b 4]
      (async done
        (-> (js/Promise.resolve 1)
            (.then #(is (= 10 (+ a b %))))
            (.finally done))))))
☝️ this fails

lilactown20:09:54

I wrote this macro to use with async tests:

(defmacro with-reset
  "Like cljs.core/with-redefs, but bindings persist until the `reset` fn is
  called, allowing bindings to be used in async contexts."
  [reset bindings & body]
  ;; code adapted from 
  (let [names (take-nth 2 bindings)
        vals (take-nth 2 (drop 1 bindings))
        orig-val-syms (map (comp gensym #(str % "-orig-val__") name) names)
        temp-val-syms (map (comp gensym #(str % "-temp-val__") name) names)
        binds (map vector names temp-val-syms)
        redefs (reverse (map vector names orig-val-syms))
        bind-value (fn [[k v]] (list 'set! k v))]
    `(let [~@(interleave orig-val-syms names)
           ~@(interleave temp-val-syms vals)
           ~reset #(do ~@(map bind-value redefs))]
       ~@(map bind-value binds)
       ~@body)))

lilactown20:09:44

using it with your code:

(def a 1)
(def b 2)

(deftest testing-async
  (testing "async testing"
    (with-reset reset [a 5 b 4]
      (async done
        (-> (js/Promise.resolve 1)
            (.then #(is (= 10 (+ a b %))))
            (.finally (fn [] (reset) (done))))))))

Otto Nascarella21:09:13

looks good! thanks!

Frosku21:09:19

Are there any good websocket sample projects (ideally with re-frame) with client AND server code?

p-himik21:09:16

Can't really speak for how good the examples are, but you can find a lot of them by using GitHub search. E.g. for Sente and re-frame: https://github.com/search?q=sente+make-channel-socket%21+re-frame&amp;type=Code Or you can search for just WebSocket and re-frame. Overall, I would recommend just reading the documentation of a library/API you want to use, checking out some trivial examples (don't have to be in Clojure), making a tiny barebone example on your own, and going from there.

Frosku21:09:12

I've read the docs, looking for an example to back those up essentially.

p-himik21:09:25

Ah, alright. I understood you mentioning re-frame as if you wanted to find some code to copy-paste.

p-himik22:09:31

Perhaps useful, although I haven't used it myself: https://github.com/7theta/re-frame-via

David Vujic05:09:09

If you haven’t seen these already, here’s some examples using the sente lib: https://github.com/ptaoussanis/sente/#example-projects