This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-09
Channels
- # aws (1)
- # babashka (61)
- # bangalore-clj (5)
- # beginners (83)
- # biff (2)
- # calva (4)
- # cider (6)
- # clara (5)
- # clj-kondo (72)
- # cljs-dev (31)
- # cljsrn (28)
- # clojure (8)
- # clojure-australia (1)
- # clojure-europe (19)
- # clojure-france (1)
- # clojure-losangeles (21)
- # clojure-nl (2)
- # clojure-spec (2)
- # clojure-uk (9)
- # clojurescript (13)
- # clojureverse-ops (5)
- # code-reviews (1)
- # conjure (7)
- # cursive (4)
- # datascript (2)
- # datomic (8)
- # depstar (1)
- # emacs (3)
- # etaoin (1)
- # events (3)
- # exercism (7)
- # fulcro (6)
- # girouette (2)
- # graalvm (125)
- # honeysql (19)
- # integrant (1)
- # jobs (12)
- # lsp (1)
- # numerical-computing (1)
- # off-topic (23)
- # portal (12)
- # practicalli (1)
- # re-frame (35)
- # reitit (5)
- # releases (1)
- # remote-jobs (1)
- # shadow-cljs (51)
- # tools-deps (14)
- # vim (3)
- # xtdb (20)
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
question about async
and with-redefs
in clojurescript: is it possible to use both?
(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 failsI 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)))
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))))))))
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: https://github.com/search?q=sente+make-channel-socket%21+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.
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: https://github.com/7theta/re-frame-via
If you haven’t seen these already, here’s some examples using the sente lib: https://github.com/ptaoussanis/sente/#example-projects