Oliver George 2020-10-24T01:22:24.229500Z

I'd be interested to see some code doing some bootstrapping stuff. It's not immediately obvious how to do a re-frame async flow seen-all-of? check for multiple independent loading actions. For example, I considered how this might translate...

(defn bootstrap
  [{:keys [db]}]
  (let []
    {:db {:ddb/state    data/empty-db
          :app/loading? true
          :app/online?  false}
     :fx [[:dispatch [::init-db]]
          [:dispatch [::init-outbox]]
          [:dispatch [::init-netinfo]]
          [:dispatch [::init-appstate]]
          [:dispatch [::load-token]]
          [:dispatch-later [{:ms 5000 :dispatch [::bootstrap.timeout]}]]
          [:async-flow {:id    ::bootstrap-flow
                        :rules [{:when     :seen?
                                 :events   [::init-db.resolve]
                                 :dispatch [::load-datoms]}
                                {:when     :seen?
                                 :events   [::load-datoms.resolve]
                                 :dispatch [::init-sentry]}
                                {:when     :seen-all-of?
                                 :events   [::netinfo-connection-status-update
                                 :dispatch [::bootstrap.succeeded]
                                 :halt?    true}
                                {:when     :seen-any-of?
                                 :events   [::log-exception ::report-anomaly-to-user ::bootstrap.timeout]
                                 :dispatch [::bootstrap.failed]
                                 :halt?    true}]}]]}))

Rafał Wyszomirski 2020-10-24T17:50:53.229900Z

Hello. Can you recommend some http client that works nicely with re-frame/cljs?

p-himik 2020-10-24T17:51:50.230Z for re-frame. It wraps cljs-ajax which you can use directly if you're not using re-frame.

Rafał Wyszomirski 2020-10-24T17:55:15.230300Z

Yes, that's what I am using currently. Unfortunately it returns response body only and I haven't found a good way to extract the whole response with status code and headers and such. Unless you know how to do it right in re-frame ;) I'm still learning so sorry if the question is obvious.

Rafał Wyszomirski 2020-10-24T17:55:43.230500Z

Other than that, I think http-fx is pretty cool

p-himik 2020-10-24T18:02:32.230800Z

Seems like specifying (ajax.ring/ring-response-format) as the response format might get you the headers and the status code. I haven't tried it though.

Rafał Wyszomirski 2020-10-24T18:05:53.231Z

Okay, thank you very much. I will try it out 👍

Rafał Wyszomirski 2020-10-24T18:23:25.231200Z

@p-himik Thanks for setting me up on the right track. I ended up using:

:response-format (ajax/ring-response-format {:format (ajax/json-response-format)})
Though I must say the documentation for it which says "`ring-response-format` takes one parameter: format" is not the same as "takes one paramater, which is a map that accepts one key only, i.e. :format that has to be one of response-formats listed earlier"... Anyway, thanks a lot 🙏

p-himik 2020-10-24T18:24:16.231500Z

Source code is always the answer. :) More often with time I tend to consult it before the documentation.

Rafał Wyszomirski 2020-10-24T18:27:15.231800Z

Yeah... I'm still getting accustomed to clj code but I was so frustrated that such an obvious thing took me 2 days...