Fork me on GitHub
#re-frame
<
2020-03-30
>
hindol17:03:41

Hi. I am new to re-frame and I am sure this is something silly, but I am getting this, re-frame: no :event handler registered for: :initialize.

;; events.cljs

(rf/reg-event-fx
 :initialize
 (fn [_ _]
   {:db       {:favourite-movies {}
               :genres           {}
               :show-only        {:genre-ids    #{}
                                  :director-ids #{}}}
    :dispatch-n [[:fetch-genres] [:fetch-favourite-movies]]}))
;; core.cljs
(ns app.core
  (:require
   [app.db]
   [app.effects]
   [app.events] ;; << required here
   [app.subs]
   [app.views]
   [reagent.dom :as rdom]
   [re-frame.core :as rf]))

(defn ^:export init
  []
  (rf/dispatch-sync [:initialize])
  (render))

lilactown17:03:30

is the reg-event-fx in the top level? or in some sort of function

lilactown17:03:45

any other errors/warnings in your browser console or compiler?

hindol17:03:22

There are a whole bunch of errors. Too much to paste here. reg-event-fx is defined as shown at ns level.

lilactown18:03:48

a whole bunch of errors might mean that some other error in your code is preventing your app.events namespace from executing, which leads to :initialize not being registered

lilactown18:03:41

I would comment out (render) from your init fn and see if those errors persist. if some of them do, then that might lead you to finding what might be causing your app.events to not execute

hindol18:03:42

This is the first error though. So I assumed this is what started it.

hindol18:03:00

But good tip. Will try that.

lilactown18:03:24

did you check to see if there are any compiler errors or warnings?

hindol18:03:58

No, shadow says build completed.

hindol18:03:05

It's all in the browser.

hindol18:03:48

Restarted shadow watch just to be sure. EDIT: Don't know what changed, but restarted shadow a few times and suddenly it worked. EDIT+: I actually remember changing in shadow-cljs.edn this line :modules    {:main {:init-fn app.core/init}} to :modules    {:app {:init-fn app.core/init}}. May be the reason why is stopped working. Now I reverted it.

thheller19:03:59

if you change the module name you must change you script tag accordingly main.js vs app.js

👍 4
hindol19:03:27

I knew it was something silly. I will remember this.