Fork me on GitHub
#re-frame
<
2022-04-02
>
fadrian13:04:14

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...

lassemaatta13:04:21

are you sure your event namespace is required somewhere?

p-himik13:04:39

The second statement says so.

🙈 1
p-himik13:04:05

Is the call to rf/reg-event-db at the top level in that namespace, and not in some function or condition?

p-himik13:04:50

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

fadrian23:04:04

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?

p-himik06:04:38

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.