Fork me on GitHub

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


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


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 [[email protected](interleave orig-val-syms names)
           [email protected](interleave temp-val-syms vals)
           ~reset #(do [email protected](map bind-value redefs))]
       [email protected](map bind-value binds)
       [email protected])))


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!


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


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:;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.


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


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


Perhaps useful, although I haven't used it myself:

David Vujic05:09:09

If you haven’t seen these already, here’s some examples using the sente lib: