Fork me on GitHub
#cljsrn
<
2019-06-16
>
worlds-endless04:06:04

In Reagent on the web, I could rely on certain elements reloading when the reagent atom changes. That doesn't seem to be working the same way for me with RN, though. I've tried being careful with my let statements, but certain components just don't seem to reload when I'd like them to (e.g. when results from an http request change the re-frame db, and the current view is supposed to checking that db data). Anyone have rules of thumb for getting React to reload more as expected?

worlds-endless05:06:43

It may have to do with my navigator setup? It looks like this...

worlds-endless06:06:57

I'm trying to implement the equivalent of an Android fragment, such that the same page can have different components depending on a db value. But only figwheel reloads seem to get me to the altered screens I want; actual app-actions that alter the db aren't causing a reload

worlds-endless06:06:06

I suspect that some combination of the react-navigate router, or reactify-component, is locking my component so it doesn't change with the db. Anyone have solutions with this sort of thing?

anish06:06:11

Hey @joshmiller and other guys who gave me suggestions about xhr issue on react-native, reason my cljs-http was not working because i was giving localhost on url, instead of localhost now i am giving me ip addrs then it works 🙂

Stefan12:06:10

Hi people, I posted a question about precise drawing in React Native on StackOverflow. Since there’s probably also a lot of expertise here, I’m taking the liberty of posting a link to my question. Any help is greatly appreciated!

Chris Swanson15:06:22

To anyone using re-frame with expo: can i make re-frame/http-fx library work? it looks like it depends on cljs-ajax, which optionally uses goog.net.XhrIo or js/XmlHttpRequest The issue is I can't just install xmlhttprequest because it uses node , which won't work in expo. I'm thinking to just fork it and cut out the node dep, since goog.net.XhrIo should be available and sufficient; does that seem reasonable, is there a better way?

danielneal16:06:25

I've been using it fine with no modifications, strangely enough

Chris Swanson16:06:05

hm , it's re-natal or expo managed ?

Chris Swanson16:06:28

wonder what i've got wrong , it said it cant find the xmlhttprequest module, so i added it to the deps, then is says it can run cause it's got a node dep

danielneal17:06:14

Hmm maybe I'm on an old version or different version somehow

Chris Swanson16:06:22

I'm thinking something like this may have a similar effect to ajax anyways:

(:require [cljs-http.client :as http])
(reg-fx
  ::http-request
  (fn [params]
    (go (let [response (<! (http/request params))]
          (dispatch [::http-response-handler response])))))

Chris Swanson16:06:52

not sure if that'll completely confuse re-frame though...

Dan Katz16:06:40

Hi all, I'm new to Clojurescript. I'm trying to invoke a function in a java based react native module. All native modules return promises in react native and I'm trying to get the ClojureScript bit right but I get a message from Node during compilation that "UnhandledPromiseRejectionWarning: Unhandled promise rejection..." . My code looks like this and to the bast of my understanding - nothing is missing: (when platform/android? (try (-> ((.-isAvailable RNTextDirection)) ;1st neative module function (.then (fn [value] (when value (-> ((.-isRTL RNTextDirection) text) ;2nd neative module function (.then (fn [value] ( (or value (right-to-left-text? text) (assoc :rtl? true)))) (.catch (fn [error] ( (right-to-left-text? text) (assoc :rtl? true)))))))) (.catch (fn [error] ( (right-to-left-text? text) (assoc :rtl? true))))) (catch js/Object err ( (right-to-left-text? text) (assoc :rtl? true)))))) Can anyone help me understand what's missing here? Thanks!

joshmiller18:06:23

@chrisjswanson I have a ~10 line fx fn that I use instead of re-frame/http-fx

joshmiller18:06:47

It’s just this:

(reg-fx
 :http
 (fn [{:keys [url method params on-success on-failure headers]
       :or {on-success [:http-no-on-success]
            on-failure [:http-no-on-failure]}}]
   (go
     (let [http-fn (case method
                     :post http/post :get http/get
                     :put http/put :delete http/delete)
           res     (<! (http-fn url {:edn-params params :headers headers}))
           {:keys [status success body]} res]
       (if success
         (dispatch (conj on-success body))
         (dispatch (conj on-failure body url)))))))

👍 8
joshmiller18:06:22

Basically the only thing most people would need to change in there would be that I am always using EDN but you might have JSON or something else

joshmiller18:06:30

That’s with cljs-http

joshmiller18:06:33

@katzdan Not exactly familiar with what that module should be doing, but ((.-isAvailable RNTextDirection)) at least is going to be an issue. The result of the inner paren is going to be a promise, but you have another paren outside of it that is attempting to eval that promise as a function.

joshmiller18:06:30

I’d start with (-> (.-isAvailable RNTextDirection) (.then some-fn) (.catch some-fn)) in the REPL and build from there.

Chris Swanson18:06:36

@joshmiller thanks , seems like the way to go

joshmiller18:06:50

I guess I should note that I also have http-no-on-success/`failure` fx fns there that default if you don’t specify, but they just log the response to the console and I only use them for debugging. But in case someone is trying to implement that and doesn’t understand what the problem is.

✔️ 4