Fork me on GitHub
#cljsrn
<
2016-03-07
>
vikeri14:03:25

@seantempesta @adamfrey : I’m starting out a new RN project and trying to decide whether to use re-frame or om-next. My initial impression is that re-frame is cleaner and more minimalistic, I like how reagent components are just data. The relay/graph-ql part of om-next is obviously quite intelligent, I’m unsure if it’ll be needed for my app though. Every user will only work with its own data and hence not as much sync with the cloud is needed and at the moment we do not have any plans on a web ui so the api endpoints will be tailored for mobile. The property based testing part should be portable to re-frame since it also has a single source of truth and serializable events. These are my initial thoughts, why did you guys choose om-next? If anyone else has experience with either I’d be grateful for your experiences.

adamfrey14:03:28

I’m using Om.next mostly because I want to really learn the query and remote fetch/mutation properties and see if they are a huge improvement in writing UIs. Frankly I’m tired of writing repetitive and inflexible backends.

seantempesta15:03:18

@vikeri: Yeah, I wanted to learn something new. At this point I’m thinking of switching to reagent (maybe Posh) and letting om.next bake a little longer.

seantempesta15:03:48

Not being able to have react components as intermediaries (ex. react-navtive-router*) is kind of rough.

vikeri15:03:43

Ok thanks! Yeah I really liked how effortless it was to include a react lib in reagent...

seantempesta15:03:52

I’ve put some decent hours into re-frame and I think it’s a solid architecture.

vikeri15:03:48

Ok good to hear! I spent a year with om (old) and re-frame seems to address the majority of the pain points we encountered in that project.

vikeri15:03:51

What are your preference on boot vs leiningen btw?

seantempesta15:03:17

I haven’t really explored boot. People I respect in the community seem to think it’s great.

jellea19:03:04

inhortte: It's js/fetch. You can use cljs-ajax for a more easy interface.

seantempesta20:03:30

@jellea: Not sure what you were referencing, but for what it’s worth I wrote some helper functions to use js/fetch that can be used to request json and process it.

(defn process-status
  "Checks the server reponse for a 200 or 0 and resolves/rejects the promise"
  [response]
  (if-let [status (.-status response)]
    (if (or (= status 200) (= status 0))
      (.resolve js/Promise response)
      (.reject js/Promise (js/Error. (.-statusText response))))))


(defn process-json
  "Calls .json on the response and resolves the promise"
  [response]
  (let [json-promise (.json response)]
    (.then json-promise #(.resolve js/Promise %))))


(defn json
  "Simplifies fetch to either succeed and parse the json or fail.
  You can specify a timeout too!"
  [url success fail max-wait]
  (let [failed? (atom false)
        fail-fn #(if (not @failed?) (do (reset! failed? true) (fail %)))
        timer (js/setTimeout #(fail-fn :timeout) max-wait)]
    (-> (js/fetch url)
        (.then process-status)
        (.then process-json)
        (.then #(when-not @failed?
                 (do (js/clearTimeout timer)
                     (success (js->clj %)))))
        (.catch #(fail-fn %)))))

jellea20:03:25

seantempesta: inhortte asked a question about it yesterday. But thanks, using transit myself though and cljs-ajax comes with support out of the box

seantempesta20:03:52

ah, gotcha. I didn’t realize it worked in react-native. Good to know.

inhortte20:03:28

@jellea Thanks. I'll have to pull the project I was playing with during the weekend up again and try cljs-ajax. I've used it before, so it makes sense.

inhortte20:03:20

@seantempesta: I tried something like your (-> (js/fetch url) (.then ...)) construct on my android emulator and it failed. I don't have the precise error in front of me at the moment, however.

seantempesta20:03:02

Hmm, I dunno. I didn’t test it on Android, but I believe the js/fetch api should also exist on Android.

inhortte20:03:38

@seantempesta: I'll try it again tomorrow and post results here. It may just be my configuration of the AVD, as I am a bit of a newbie in this arena.