This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-27
Channels
- # announcements (1)
- # aws (8)
- # babashka (77)
- # babashka-sci-dev (8)
- # beginners (29)
- # biff (2)
- # calva (13)
- # cljs-dev (1)
- # clojure (42)
- # clojure-europe (205)
- # clojure-nl (1)
- # clojure-norway (5)
- # clojure-uk (4)
- # clojurescript (58)
- # conjure (9)
- # data-science (7)
- # datalevin (19)
- # datomic (3)
- # emacs (7)
- # fulcro (15)
- # gratitude (8)
- # lsp (52)
- # meander (3)
- # membrane (92)
- # off-topic (12)
- # re-frame (16)
- # reagent (4)
- # reitit (15)
- # releases (1)
- # sci (30)
- # shadow-cljs (34)
- # tools-deps (5)
- # xtdb (17)
hello there, has anyone out there been crazy enough to use var
s as id
for reg-event-*
and reg-sub
?
IIRC there’s no requirement that id
needs to be a keyword.
Or is there?
Here’s an example:
(defn submit [db] (assoc db :bubu :lala))
(defn bubu [db] (:bubu db))
(rf/reg-event-db #'submit #'submit)
(rf/reg-sub #'bubu #'bubu)
(rf/dispatch [#'submit])
@(rf/subscribe [#'bubu])
=> :lala
This gives you compile-time checks on dispatches/subscriptions, but now you need to organize the order of your fns or use declare
Using var instead of symbol allows for re-binding of submit/bubu.
What are cons I’m not thinking of?is that because the names can’t be minified?
i.e. why is that different from (rf/reg-sub ::submit submit)
new cljs.core.Var(
function () {
return hello.world.example;
},
new cljs.core.Symbol(
"hello.world",
"example",
"hello.world/example",
2147299913,
null
),
cljs.core.PersistentHashMap.fromArrays(
[
new cljs.core.Keyword(null, "ns", "ns", 441598760),
new cljs.core.Keyword(null, "name", "name", 1843675177),
new cljs.core.Keyword(null, "file", "file", -1269645878),
new cljs.core.Keyword(null, "end-column", "end-column", 1425389514),
new cljs.core.Keyword(null, "column", "column", 2078222095),
new cljs.core.Keyword(null, "line", "line", 212345235),
new cljs.core.Keyword(null, "end-line", "end-line", 1837326455),
new cljs.core.Keyword(null, "arglists", "arglists", 1661989754),
new cljs.core.Keyword(null, "doc", "doc", 1913296891),
new cljs.core.Keyword(null, "test", "test", 577538877),
],
[
new cljs.core.Symbol(
null,
"hello.world",
"hello.world",
1080792214,
null
),
new cljs.core.Symbol(null, "example", "example", -115247617, null),
null,
14,
1,
18,
18,
cljs.core.list(cljs.core.PersistentVector.EMPTY),
null,
cljs.core.truth_(hello.world.example)
? hello.world.example.cljs$lang$test
: null,
]
)
)
includes all metadata and stuff. :advanced
will shrink this a little but still a substantial amount more than just re_frame.core.reg_sub(new cljs.core.Keyword(null, "submit"), your.ns.submit)
thanks for the insight. Very useful. I guess if I use symbols instead, I’d have to deal with re-registering subs and events to make sure they resolve to the correct fn
for the shadow-cljs UI (not re-frame) I went with tagging event functions via metadata and then having a macro find them all and reg-sub/event'ing it basically https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/cljs/ui/db/generic.cljs#L11
This isn't supported in re-frame, but Danny Freeman has a tiny lib that lets you use plain functions as subscriptions: https://git.sr.ht/~dannyfreeman/repose the main advantages are jump to definition integration for editors as well as proper module splitting/code motion support
I am honored to have you out here hawking my wares @U051V5LLP. I need to circle back to that library and make it production ready 🙂 The event system is really primitive.