Fork me on GitHub
#cljsrn
<
2017-06-03
>
iwsfutcmd00:06:24

hey, i'm working on my first cljs rn project right now and i'm trying to figure out a decent way to make API calls to our server. i've got an ugly partial-solution using js/fetch, but it looks like (as my friend says) "Javascript with parens", and i'm getting into trouble when having to make multiple API calls to fill one resource. anybody got any good direction for me to look?

j-po00:06:21

Hi! I'm the friend! The concern I was voicing was that resetting state atoms inside of nested .then calls (on a js/fetch promise) set off my "there must be a better way" sense (either a way to bring the process closer to clojure semantics or a way to bubble updating app state up to a higher call site). I could be totally wrong—cljs is not a particular area of my expertise.

nikki04:06:14

i believe there is something out there that makes promises and core.async channels play nicely w/ each other

nikki04:06:21

also there is 'promesa'

nikki04:06:06

Which part do u think u want: something that runs in cljs and does network requests nicely, or something that wraps promises nicely and u continue using fetch?

nikki04:06:31

if u think u have many js promisy apis u wanna use directly the latter may make more sense, if this is basically the only one the former could

nikki04:06:55

@carocad yeah i understand it pretty well

nikki04:06:13

it shims goog.require because the normal impl needs a browser context to load js

nikki04:06:22

then it also shims goog.net.jsloader for the same

nikki04:06:35

the component thing is to allow cljs to jack in a root component async'ly after it runs

nikki04:06:45

all of this is for the figwheel loaded case

nikki04:06:16

in the case of making a huge js compiled single bundle of ur app (like for 'prod') this is all irrelevant

nikki04:06:54

The boot-expo thing i released recently basically does figwheel-bridge in way fewer lines in main.js https://github.com/nikki93/boot-expo/blob/master/main.js

nikki04:06:29

figwheel-bridge does some weird wait loop stuff to eval the received js in the right order; my version just does a "right fold" through time of promises ;)

carocad15:06:55

nikki: have you by any chance posted this in a blog or similar? I would like to add some docs to re-natal. The more information I have the better 😀

iwsfutcmd05:06:14

@nikki thanks! so i'm not dedicated to using js/fetch or anything, i just figured it'd be the best way to try to get it to work, as it seems like it's being encouraged as the way to go for http requests in javascript ("future-proof" i think i read somewhere). that being said, i'm doubting i'm going to be using any additional promises other than http requests. so i'm not sure which approach would be best.

iwsfutcmd05:06:56

oh, and i'm developing primarily for Android (at first) and i had read here: https://github.com/JulianBirch/cljs-ajax/issues/141 that calling XmlHttpRequest was giving people headaches, so that's why i was leaning more towards fetch. but again, no loyalty, just trying to make things easy on myself

nikki06:06:09

@domkm may be able to offer u advice on this tbh

domkm01:06:17

@iwsfutcmd The only thing we had to do to get Promesa to work was add an empty org.bluebird namespace to prevent Promesa from loading the real Bluebird library.

nikki06:06:15

he has used promesa

urbank23:06:32

pardon the lack of specificity, but using re-natal what could be causing figwheel repl not to connect, and saving files not to hot-reload the application?

urbank23:06:50

it does open on my device after running react-native run-android

urbank23:06:07

but it doesn't update when I change the code

urbank23:06:02

I now enabled hot reloading and live reloading

urbank23:06:31

But the figwheel has still not connected

nikki23:06:11

disable both of those

nikki23:06:41

and try lein figwheel at cmdline and manually reload app on phone once

nikki23:06:30

but also make sure it's got the right way to connect to ur computer as a server, be that a LAN ip/hostname or ngrok tunnel or whatever

domkm01:06:17

@iwsfutcmd The only thing we had to do to get Promesa to work was add an empty org.bluebird namespace to prevent Promesa from loading the real Bluebird library.