I see an example of Ajax call in the re-frame docs:
(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)}))
Can I just call the event in the main function:
(reframe/dispatch-sync [:request-it])
to load the initial values? I need to load the initial values and then render the views.
UPDATE
I did it using this function:
(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))))))