This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-02
Channels
- # asami (5)
- # aws (16)
- # babashka (41)
- # babashka-sci-dev (44)
- # beginners (157)
- # biff (3)
- # cider (1)
- # clj-commons (1)
- # cljdoc (22)
- # clojure (7)
- # clojure-dev (5)
- # clojure-europe (13)
- # clojure-nl (1)
- # clojure-uk (1)
- # clojurescript (17)
- # core-typed (13)
- # cursive (14)
- # datascript (10)
- # events (1)
- # fulcro (2)
- # graalvm (2)
- # gratitude (1)
- # jobs (3)
- # lsp (229)
- # pathom (2)
- # pedestal (3)
- # portal (53)
- # re-frame (7)
- # remote-jobs (1)
- # spacemacs (14)
- # xtdb (6)
I have an event handler declared in the file event.cljs (ns atlas.event):
(rf/reg-event-db
:set-rule-editor-context-selector
(fn [db [_ ctxt-id red-id]]
(assoc-in db [:rule-editor-state red-id :ctxt-selector] ctxt-id)))
I call this from the file editor.cljs (ns atlas.editor which requires atlas.event):
(defn rule-editor-header
[rule-editor-id ctxt-sel-id]
(rf/dispatch [:set-rule-editor-context-selector ctxt-sel-id rule-editor-id])
(fn [rule-editor-id ctxt-sel-id]
;... more React type-2 stuff
However, whenever I dispatch on this handler, I get the following error:
./cljs-runtime/cljs.core.js:13642 re-frame: no :event handler registered for:
{ns: null, name: 'set-rule-editor-context-selector', fqn: 'set-rule-editor-context-selector', _hash: -617008016, cljs$lang$protocol_mask$partition0$: 2153775105, …}
cljs$lang$protocol_mask$partition0$: 2153775105
cljs$lang$protocol_mask$partition1$: 4096
fqn: "set-rule-editor-context-selector"
name: "set-rule-editor-context-selector"
ns: null
_hash: -617008016
[[Prototype]]: Object
Any idea why this particular event handler is throwing this error? None of my other handlers seem to have this issue...are you sure your event namespace is required somewhere?
Is the call to rf/reg-event-db
at the top level in that namespace, and not in some function or condition?
Also, are you sure it's that exact call to dispatch
that causes the error?
Two somewhat related notes:
• You probably don't want to dispatch there - that goes against the whole re-frame model, and it will be dispatched only on the mount so it won't be re-dispatched when any of those parameters change (but maybe that's what you want)
• Use cljs-devtools
Thanks, as usual, for your help. It was indeed an issue of a misplaced closing parenthesis and the event was not declared at the top-level. Fixing that fixed the thrown errors. I did want to put that association in the mount - the event associates the id for the context selector contained in the rule-selector with the rule-selector. This way, when the context selector sends a change message to its parent object, the parent object knows which context selector to get its context state from. Is there a better way to structure this in re-frame?
There is, and although some people debate what "better" means here, at least that way would be according to the re-frame world view. https://day8.github.io/re-frame/FAQs/LoadOnMount/ And to help with the workflow described in the "Do This Instead" section, there are global interceptors that might or might not be useful in your case.