This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-01
Channels
- # aleph (3)
- # announcements (10)
- # babashka (6)
- # bangalore-clj (4)
- # beginners (91)
- # biff (7)
- # cider (25)
- # cljs-dev (1)
- # clojure (109)
- # clojure-europe (9)
- # clojure-norway (5)
- # clojure-uk (1)
- # clojurescript (22)
- # cursive (22)
- # data-science (1)
- # datalevin (5)
- # datomic (7)
- # emacs (7)
- # etaoin (1)
- # events (3)
- # graphql (12)
- # hyperfiddle (1)
- # inf-clojure (1)
- # lsp (69)
- # luminus (1)
- # meander (21)
- # nbb (4)
- # off-topic (27)
- # other-languages (12)
- # rdf (58)
- # releases (3)
- # remote-jobs (2)
- # rum (12)
- # shadow-cljs (4)
- # sql (3)
- # xtdb (1)
I noticed a discrepancy between Clojure and ClojureScript when it comes to extend-protocol
. Take the following two impls:
(require '[my.protoocols :as p])
;; Impl 1: Namespaced protocol fn
(extend-protocol p/Foo
string
(p/-foo [s] (foo-fn s))) ; Namespace
;; Impl 2: No namespace on protocol fn
(extend-protocol p/Foo
string
(-foo [s] (foo-fn s))) ; No namespace
Both impls would work in Clojure, but only the second works in ClojureScript. If I do the first I’d get this error:
; WARNING: Use of undeclared Var my.protocols/p/-foo at line 1 <cljs repl>
; Execution error (TypeError) at (<cljs repl>:1).
; Cannot read properties of undefined (reading '_foo_')
I suspect the first one working in Clojure is more accident than intent
yeah, the namespace of that p/-foo is not even looked at (could be anything)
the name is the important part
this behavior should be considered undefined and thus both clj and cljs are not wrong (but probably Clojure should complain about this)
the second example is the correct way
Is there conditional compilation available for nodejs? Let me explain -- let's say I have this chunk of code.
(defn foo []
(something something)
(-> (.. js/document (querySelector ".foo"))
something
something))
If I want to do conditional compilation for clojure, I can put this in a .cljc
file and put in the appropriate reader conditionals. But if I want to reuse browser code on nodejs (let's say for lambda functions), the js/document
will throw an error.
Now, I know I can shim it out, but wondering if there's a more elegant way.in official clojurescript: no, but with shadow-cljs: yes https://shadow-cljs.github.io/docs/UsersGuide.html#_conditional_reading
interesting, thanks!
Hello there! Quick question, what do you use to consume rest api's in clojurescript? Do you use js/fetch or some other library?
I've had luck with
but you're probably better off writing a light wrapper around js/fetch
depending on your comfort level.
Ah nice, I've stumbled upon this too: https://github.com/r0man/cljs-http I'm just making a quick poll to see what people here use
I like that one but it doesn't support certain things I needed like DELETE
so depends on your use case
There's a few weird quirks with cljs-ajax. One of the params it accepts is a :handler
argument which is a callback. You can do a pattern like
(defn my-post [opts]
(a/go
(let [done? (a/promise-chan)]
(ajax/post
(merge opts
:handler
(fn [data]
(swap! some-atom some-func data)
(a/offer! done? true))))
done?))
(my parens may be out of whack there)
that would then make my-post
an async function
So yeah at that point might as well use fetch since the API will be more up-to-date
> ...but you're probably better off writing a light wrapper around js/fetch
depending on your comfort level.
If you don't want to write your own wrapper, there is https://github.com/lambdaisland/fetch