6

我的重新框架 views.cljs 有:

(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]])

我的 events.cljs 有:

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

但我不断收到此错误:

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

4

2 回答 2

4

解决方案是包含nil查询变量

(re-frame/dispatch
 [::re-graph/query
  "{launches {id, mission_name}}"
  nil
  [:add-launches]])
于 2019-06-20T06:04:26.787 回答
2

你应该:events/update-dataviews.cljs. ::引用当前命名空间 ( ) :views/update-data,并且该事件处理程序没有定义在那里,而是在events命名空间中。

另请注意,您可以使用:

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

为您节省一个assoc

于 2019-06-19T13:36:18.900 回答