Fork me on GitHub

folks, anyone figured out how to use re-frame-http-fx on React Native? I can’t get it to work because of failing dependency on xmlhttprequest module


@xfyre I got it working by just copying the source file to my project and installing dependencies manually. This was last December so things may have changed since.


@valtteri actually I figured out what the problem is, but didn’t figure out a solution yet one obvious workaround is downgrading re-frame-http-fx to 0.1.4


@xfyre I think I encountered the same issue but I can’t remember the exact details. 😕 From git it seems like I’ve ended up copying the source of re-frame-http-fx under src and declaring dependency to cljs-ajax manually in project.clj. I’ll try to see if I can find any notes why I ended up doing exactly that.


Nah, apparently I didn’t make any notes but I hope you’ll find the solution that works for you also.

Garrett Hopper20:09:16

Can someone give me some guidance on dealing with promises in re-frame? I have a client API that returns promises, though I can't figure out how to handle it.

 :<- [:credentials]
 (fn [credentials]
   (when credentials
     (create-client credentials))))

 (fn [_]
   (let [a      (r/atom nil)
         client @(rf/subscribe [:client])]
     (.then (.query client)
            #(reset! a (js->clj %)))
     (ratom/reaction @a))))
Part of the problem is that in order to create my client, I need to do some credentials federation first, so (rf/subscribe [:client]) is nil for the first few seconds. I've tried a number of ways of having the @(rf/subscribe [:client]) inside the reaction, but the problem is that it causes an endless loop.

Garrett Hopper20:09:45

Essentially, whenever [:client] changes, I need to issue the request, however I don't want to reissue the request once the r/atom (or db) changes.

Garrett Hopper20:09:27

Is there a cleaner way than this?

 (fn [_]
   (let [a (r/atom nil)
         b (ratom/reaction
            (let [client @(rf/subscribe [:client])]
              (when client
                (.then (.query client)
                       #(reset! a %)))))]
      (fn [] @a)
      :on-dispose #(ratom/dispose! b)))))