This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-16
Channels
- # adventofcode (24)
- # announcements (3)
- # aws (3)
- # babashka (16)
- # beginners (88)
- # biff (5)
- # calva (27)
- # cider (15)
- # cljs-dev (70)
- # clojure (87)
- # clojure-austin (3)
- # clojure-belgium (6)
- # clojure-europe (59)
- # clojure-nl (1)
- # clojure-norway (14)
- # clojure-uk (3)
- # clojurescript (37)
- # data-science (2)
- # datalevin (40)
- # datomic (1)
- # emacs (23)
- # events (2)
- # graalvm (13)
- # graphql (7)
- # gratitude (1)
- # holy-lambda (193)
- # inf-clojure (15)
- # lsp (27)
- # malli (9)
- # off-topic (20)
- # polylith (6)
- # reitit (29)
- # releases (2)
- # scittle (13)
- # shadow-cljs (51)
- # transit (15)
- # xtdb (29)
if i have a protocol fn (expand [_ _])
and try to call it like (expand :some-keyword {:a 1})
i get the same map in both arguments
if i have a protocol fn (href [_] [_ _] [_ _ _])
then trying to call it as (href ::some-keyword)
will error saying there's no implementation for the protocol for null
Can you share more code? It seems like you are not passing the type that implements the protocol as first argument
E.g. do you use defprotocol
and extend-protocol
? Or extend-type
or reify
?
Can you share how you use defprotocol and extend-protocol?
the first arg is always the thing that implements the protocol. so if you don't implement it for keywords you get an error
Uncaught Error: No protocol method ByName.href defined for type null:
when the callsite is hard coded to this:
(href ::web/ping)
it very likely doesn't. did you verify that you are looking at your exact piece of code? ie. by commenting it out?
and you implemented the prtocol in a non-recursive fashion where it calls itself, which maybe some other logic you did?
Hmm that narrowed it down a little. So I have this protocol
(defprotocol ByName
(href [_] [_ _] [_ _ _]))
Implemented for Keyword like this
(extend-protocol routes/ByName
Keyword
(href
([route]
(js/alert "a" route)
(href route nil nil))
([route params]
(js/alert "b" route)
(href route params nil))
([route params query]
(js/alert "c" route)
(easy/href route params query))))
I get alert "a" out of this but never alert "b".
The super annoying thing about this is that this exact code (without the alerts of course) works without problem in another project (where the protocol is defined in a cljs file and not a cljc)Similarly I have a protocol
(defprotocol Expand
(expand [_ _]))
Implemented like this
(extend-protocol routes/Expand
Keyword
(expand
[route-name opts]
(expand {:name route-name} opts))
PersistentArrayMap
(expand
[{route-name :name :as route} _]
(conj route (route-defs route-name)))
PersistentHashMap
(expand
[{route-name :name :as route} _]
(conj route (route-defs route-name))))
And even if I call this like (expand :foo {})
it matches on the PersistentArrayMap just throwing the keyword away (the Keyword implementation never gets called -- confirmed with console.logs)I have never seen cljs behave like this and I got no idea what I could've messed up. I've tried clearing the .shadow-cljs and public/js folders, no luck.
here i committed it https://github.com/valerauko/shared-routing/blob/main/src/shared_routing/router.cljs
i understand that. i just realized that in this case href
doesn't have to be a protocol.
that however doesn't explain the issue with the protocol that has a sinlgle [ ] arity
but the protocol is in another namespace, so why is this not qualified? or do you have a refer?