Fork me on GitHub
#re-frame
<
2017-05-24
>
souenzzo01:05:52

How to get headers from http response on cljs-ajax/http-fx??

fbielejec14:05:28

souenzzo: not that straightforward

fbielejec14:05:56

` (:require [ajax.core :refer [GET POST ajax-request detect-response-format text-request-format text-response-format]]) (:import [http://goog.net XhrIo]) (defn response-handler [[ok xhrio]] (if ok (let [response (.getResponse xhrio) headers (.getAllResponseHeaders xhrio)] (re-frame/dispatch [:response-convert {:response response :headers headers}])) (let [error-response (.getResponse (:response xhrio)) headers (.getAllResponseHeaders (:response xhrio))] (re-frame/dispatch [:response-convert {:response error-response :headers headers}])))) (def request {some-request-map}) (ajax-request {:uri "/enpoint" :method (:method request) :headers (:headers request) :params (:body request) :format (text-request-format) :response-format {:read identity :description "raw"} :handler repsonse-handler})`

fbielejec14:05:38

but your server also need to expose the headers, so in the handler for /endpoint it needs to add to response:

fbielejec14:05:39

(assoc-in response [:headers "Access-Control-Expose-Headers"] "Access-Control-Allow-Headers,Access-Control-Allow-Methods,Access-Control-Allow-Origin,Content-Length,Date,Server")

souenzzo14:05:37

I will try, but I'm using cljc. I will see

fbielejec14:05:19

in that case I think clj-http exposes headers on the response, so maybe try:

fbielejec14:05:21

[clj-http.client :as http] response (http/post "/endpoint" {:headers (:headers request) :body (:body request)}) (select-keys response [:headers :body])

danielgrosse12:05:49

How can I merge multiple dbs?

souenzzo13:05:26

danielgrosse: (merge db-1 db2)?

danielgrosse20:05:48

But when I start the app, I initialize the database with re-frame dispatch. When I add a component with its own db to the app and initialize that db at loading, do I have to merge the db in the init event?

souenzzo02:05:43

in "`re-frame` way of life", you dont have local state. Somewhere in tutorial has a section about "single source of true"

fbielejec14:05:28

souenzzo: not that straightforward

fbielejec14:05:56

` (:require [ajax.core :refer [GET POST ajax-request detect-response-format text-request-format text-response-format]]) (:import [http://goog.net XhrIo]) (defn response-handler [[ok xhrio]] (if ok (let [response (.getResponse xhrio) headers (.getAllResponseHeaders xhrio)] (re-frame/dispatch [:response-convert {:response response :headers headers}])) (let [error-response (.getResponse (:response xhrio)) headers (.getAllResponseHeaders (:response xhrio))] (re-frame/dispatch [:response-convert {:response error-response :headers headers}])))) (def request {some-request-map}) (ajax-request {:uri "/enpoint" :method (:method request) :headers (:headers request) :params (:body request) :format (text-request-format) :response-format {:read identity :description "raw"} :handler repsonse-handler})`

fbielejec14:05:19

in that case I think clj-http exposes headers on the response, so maybe try:

chrishacker15:05:56

Anyone have any suggestions or insights into getting react-virtualized to work in a re-frame application? I think we're having low level dependency conflicts with react itself being included by reagent and other libraries. We're working through that to see, but I am hoping someone has had success before. Thanks.

danielgrosse20:05:48
replied to a thread:How can I merge multiple dbs?

But when I start the app, I initialize the database with re-frame dispatch. When I add a component with its own db to the app and initialize that db at loading, do I have to merge the db in the init event?