1

re-frame docs に Ajax 呼び出しの例があります。

(reg-event-fx        ;; <-- note the `-fx` extension
  :request-it        ;; <-- the event id
  (fn                ;; <-- the handler function
    [{db :db} _]     ;; <-- 1st argument is coeffect, from which we extract db    
    ;; we return a map of (side) effects
    {:http-xhrio {:method          :get
                  :uri             "http://json.my-endpoint.com/blah"
                  :format          (ajax/json-request-format)
                  :response-format (ajax/json-response-format {:keywords? true}) 
                   :on-success      [:process-response]
                   :on-failure      [:bad-response]}
     :db  (assoc db :loading? true)}))

メイン関数でイベントを呼び出すことはできますか:

 (reframe/dispatch-sync [:request-it])

初期値をロードするには?初期値をロードしてから、ビューをレンダリングする必要があります。

アップデート

私はこの関数を使用してそれを行いました:

(reframe/reg-event-db
  :process-response
    (fn
      [db [_ response]]
        (-> db
          (assoc :loading?  false)     ;; take away that "Loading ..." UI
          (assoc :test      (js->clj response))
          (assoc :questions (js->clj (:questions response))))))
4

0 に答える 0