Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

re-frame: No event handler registered

My re-frame views.cljs has:

(re-frame/dispatch [::re-graph/init
                    {:http-url "https://api.spacex.land/graphql"
                     :ws-url nil
                      :http-parameters {:with-credentials? false}}])

(re-frame/dispatch [::re-graph/query
                    "{ launches { id, mission_name } }"  ;; your graphql query
                    [::update-data]])

My events.cljs has:

(re-frame/reg-event-db
 ::update-data
 (fn [db [_ {:keys [data errors] :as payload}]]
   (-> db
     (assoc :errors errors)
     (assoc :data data))))

But I keep getting this error:

core.cljs:3919 re-frame: no :event handler registered for: undefined

like image 876
jwesonga Avatar asked Jun 18 '19 05:06

jwesonga


2 Answers

The solution is to include the nil for the query variables

(re-frame/dispatch
 [::re-graph/query
  "{launches {id, mission_name}}"
  nil
  [:add-launches]])
like image 79
jwesonga Avatar answered Sep 20 '22 18:09

jwesonga


You should use :events/update-data in views.cljs. The :: refers to the current namespace (:views/update-data), and that event handler is not defined there, but in the events namespace.

Also note that you can use:

(-> db
   (assoc :errors errors
          :data data)))

saves you one assoc.

like image 38
Erwin Rooijakkers Avatar answered Sep 24 '22 18:09

Erwin Rooijakkers