This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-07
Channels
- # announcements (5)
- # asami (17)
- # aws (11)
- # babashka (67)
- # beginners (90)
- # calva (13)
- # cider (17)
- # circleci (6)
- # clj-kondo (3)
- # clojure (53)
- # clojure-europe (12)
- # clojure-france (8)
- # clojure-germany (3)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-norway (4)
- # clojure-spec (15)
- # clojure-uk (8)
- # clojurescript (41)
- # cursive (7)
- # data-science (6)
- # datomic (8)
- # emacs (10)
- # exercism (1)
- # figwheel-main (2)
- # fulcro (5)
- # graalvm-mobile (97)
- # graphql (1)
- # hyperfiddle (7)
- # inf-clojure (6)
- # interop (4)
- # introduce-yourself (5)
- # jobs (3)
- # kaocha (3)
- # malli (8)
- # meander (8)
- # music (3)
- # nrepl (7)
- # observability (1)
- # off-topic (45)
- # overtone (2)
- # polylith (63)
- # portal (2)
- # re-frame (26)
- # reveal (8)
- # ring (3)
- # shadow-cljs (56)
- # tools-build (5)
- # vim (11)
- # xtdb (8)
How do I call a namespaced effect (`::effect`) from an event? {:effect "Something"}
doesn't work and produces a re-frame: no handler registered for effect:
error.
Just use the correct keyword?
If your effect is in ns a.b
and your event handler is in ns b.c
, then use :a.b/effect
.
Or add [a.b :as b]
to your :require
and use ::b/effect
.
How does one call a reg-sub
from an event using it as a parameter to an effect? Eg. I have an event, ::copy-path
, which returns the result of an effect ::b/copy
, the parameter for ::b/copy
should be string returned by a reg-sub
::path
.
An easy and correct way is to deref the sub in the relevant view and pass the value itself as a part of the event vector. There's an FAQ entry for that.
In general do subs need to be put at the top of the view, or can sub-views have subscriptions as well? Troubleshooting some subscription problems and trying to rule stuff out.
I thought maybe my problems were related to subscriptions in nested components, but that can't be it.. I think its related to de-refing subs in let statements instead of function bodies.. tracking down a very silent subscription-not-running problem
So far, what you describe doesn't make much sense. If you can't figure it out, create a minimal reproducible example and I'll take a look.
As a guess, if you have code like this then the component will not be re-rendered on the sub change:
(defn component []
(let [v @(rf/subscribe [...])]
(fn []
[:div v])))
What about
(defn component []
(let [v (rf/subscribe [...]
[x (+ 1 @v)]
(fn []
[:div x])))
Same thing. Why do you even use a form-2 component? Just make it a form-1 one and that's it.
When you have state that should persist between re-renders of the component or when you have some setup code that should be run before the very first mount.
And even then, you often can use reagent.core/with-let
instead - sometimes it makes things shorter and more natural.
Got an event here:
(reg-event-fx
::copy-something
(fn [{:keys [db]}]
{::effect/copy (:something db)}))
However, this doesn't fetch :something
from db What is the correct way to pull data from db?That's how you do it. Inspect whether db
is in the state that you expect it to be in.
How do I inspect db? I've been using (js/console.log)
but that doesn't show any of the data in the db.
Two ways - either (js/console.log db)
with cljs-devtools
installed or re-frame-10x
.
If the former doesn't show any data (i.e. it shows null
), then you broke your DB somewhere before that event.
A good thing to have is a global interceptor that checks your DB against the spec after every single event.
The console log value I get is:
{meta: null, cnt: 42, root: {…}, has_nil_QMARK_: false, nil_val: null, …}
cljs$lang$protocol_mask$partition0$: 16123663
cljs$lang$protocol_mask$partition1$: 139268
cnt: 42
has_nil_QMARK_: false
meta: null
nil_val: null
root: {edit: null, cnt: 23, arr: Array(32), cljs$lang$protocol_mask$partition1$: 131072, cljs$lang$protocol_mask$partition0$: 0}
__hash: null
[[Prototype]]: Object
Right, you should install cljs-devtools
- it'll make your life much easier. What you see above is a JS representation of a CLJS object.
Any other way to inspect the db? I'll have to discuss adding cljs-devtools
. re-frisk
is already available to the project.