This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-30
Channels
- # adventofcode (4)
- # aleph (1)
- # announcements (7)
- # aws (10)
- # babashka (23)
- # beginners (23)
- # calva (20)
- # chlorine-clover (13)
- # cider (17)
- # clj-kondo (13)
- # cljfx (9)
- # cljsrn (9)
- # clojure (98)
- # clojure-australia (1)
- # clojure-dev (15)
- # clojure-europe (127)
- # clojure-nl (4)
- # clojure-sanfrancisco (3)
- # clojure-uk (98)
- # clojurescript (25)
- # community-development (8)
- # core-async (15)
- # cryogen (9)
- # cursive (7)
- # data-science (1)
- # datascript (5)
- # datomic (3)
- # devcards (2)
- # fulcro (5)
- # graalvm (1)
- # helix (8)
- # jackdaw (1)
- # jobs (5)
- # kaocha (17)
- # malli (5)
- # meander (5)
- # off-topic (37)
- # pathom (33)
- # pedestal (3)
- # re-frame (12)
- # reitit (1)
- # remote-jobs (3)
- # sci (1)
- # shadow-cljs (6)
- # testing (1)
- # vim (6)
- # vrac (5)
Is there a linter that catches cases such as dispatching a non-existent event or subscribing to a non-existent subscription? I guess it'd be fairly straightforward to build something on top of e.g. https://github.com/jpmonettas/clindex, but I was just wondering whether something like that already exists.
FWIW, I've never seen anything like that being mentioned. I'm not sure it would be that straightforward given that event/sub IDs can be anything and not just keywords. And you can dynamically create them, even if they're just keywords.
Right, good point. I think it might be possible to catch most cases, but you're right that a static analysis type of approach wouldn't catch everything.
It's just a very easy bug to make to forget to update the event names in dispatch calls when moving things around.
If it's a problem you could def symbols for every reframe sub and event by convention (I'd put them all in one namespace) and get compile time assistance / potentially better refactoring support from your editor.
Hmm, interesting idea, thanks. Might get a bit boilerplatey, but it might work. I'll consider it.
When you deref a non existing subscription it throws an error?
It does, but you’ll have to open the console to see that. Of course, could maybe make it throw an error to make it more visible. :thinking_face:
In so many instances I’ve had nil subscriptions completely blank the page so it was hard for them to go unnoticed 😂
Sometime ago someone linked here a neat def-sub
macro:
(defmacro def-sub [name & args]
{:pre [(symbol? name)]}
(let [kw (keyword (ns-name *ns*) (str name "|sub"))]
`(do
(def ~name ~kw)
~(macroexpand `(rf/reg-sub ~kw ~@args)))))
And that can be done for event handlers also. I'm seriously considering starting to use that. I think the benefits are quite big: Easier code navigation (jump to definition), linter warnings when trying to use undefined event/subscription etc.