Fork me on GitHub
#cljsrn
<
2016-03-03
>
sllyq03:03:10

Hello I'm trying to create a react native app with reframe and have set up a re-natal project but I'm not sure how to do navigation, can anyone linke me to some good resources?

alwx13:03:43

I have an interesting question for you, guys

alwx13:03:26

How can I make my GET requests work? simple_smile I need to execute them async, and seems like cljs-ajax or cljs-http don't work in my case. Maybe it is because of CORPS, but I don't know how to fix it.

alwx13:03:17

The most interesting thing is that calling js/Fetch works perfectly. But I don't know how to execute everything asynchronously in this case.

artemyarulin13:03:48

@alwx: Could be that those libs rely on window/document which is not available

artemyarulin13:03:04

although you can use fetch or standard XmlHTTRequest

alwx13:03:21

(register-handler
  :monitoring
  (fn [db [_ {:keys [session]}]]
    (let [req (js/fetch (str config/api-url "/monitoring?session=" session))]
      (-> req
          (.then (fn [response]
                   (.text response)))
          (.then (fn [responseText]
                   (let [response (-> (.parse js/JSON responseText)
                                      (js->clj)
                                      (keywordize-keys)
                                      :data)]
                     (dispatch [:get-data-success [:monitoring response]]))))
          (.catch (fn [error]
                    (dispatch [:get-data-failure [:monitoring error]])))))
    (assoc-in db [:data :loading?] true)))

alwx13:03:31

I use Fetch this way. It is a bit ugly, but it works

artemyarulin13:03:51

so, what it the issue then? simple_smile

alwx13:03:58

But how can I run it asynchronously? simple_smile

artemyarulin13:03:11

Am, everything is async

alwx13:03:35

official documentation suggests the following:

async getUsersFromApi() {
  try {
    let response = await fetch('');
    let responseJson = await response.json();
    return responseJson.users;
  } catch(error) {
    // Handle error
    console.error(error);
  }
}

artemyarulin13:03:35

it’s a promise which are async

artemyarulin13:03:32

Hm, I’m not following - all IO in react native is async by default, fetch uses promises under the hood in order to handle it a bit easier

artemyarulin13:03:11

>Using then and catch in synchronous code:

artemyarulin13:03:35

got it - I guess this is a mistake in documentation. All IO is async and you cannot have sync promises actually. You code is 100% async and await and async keywords are processed by babel which generates promise code at the end, so no difference

skottk13:03:00

OS/X El Capitan.

adamfrey13:03:57

which version of react-native is in your package.json?

drapanjanas17:03:23

@skottk have you tried running vanilla js RN app? Does it work?

skottk17:03:26

Had no trouble with a vanilla natal app.

shaun-mahood20:03:17

Not a guarantee at all, but there is a possibility my company may be contracting out some iOS app development in the reasonably near future. Not sure of scope or anything like that, but it should be reasonably simple and would be created from scratch. Is anyone here interested in discussing something like that if it does come to pass?