Fork me on GitHub
#clojurescript
<
2018-09-22
>
yogidevbear13:09:31

Hi everyone. I'm curious as to which approaches and tooling you think are best/preferred for making mobile apps using ClojureScript? Cljsrn, reagent, Cordova, Expo, etc?

pesterhazy13:09:21

@yogidevbear re-natal is the most mature option out there. Any React wrapper will work with it, but Reagent is the most common.

yogidevbear13:09:31

Cool thanks for the feedback 👍 I was just reading through the homepage on http://cljsrn.org when you pinged me

awb9915:09:18

I made a function that gets me json data from an url. Now I want use this function in other functions that get useful data. I thought I could use promises for that. And with "promesa" library it works. However I get back a promise that seems to be a javascript object. And as such I think I will then have to deal with javascript all over my clojurescript code. Any ideas? Am I on the wrong track with this approach?

pesterhazy15:09:53

@hoertlehner, first, you don't need to wrap the whole thing in a promise

awb9915:09:50

Do you know how I can get the resolved value of the promise?

awb9915:09:58

my function returns back a promise,

awb9915:09:14

and with println I can see the promise and its resolved value,

pesterhazy15:09:21

(.then p (fn [r] (prn r)))

awb9915:09:30

with .then

pesterhazy15:09:31

remember this will by async

awb9915:09:50

of course,

pesterhazy15:09:57

Promises have a tiny API - the constructor, .then and .catch - that's it

awb9915:09:08

in JS I normally use .then only when I want to chain the computation.

awb9915:09:15

if I got a promise I normally do await promise,

awb9915:09:18

and then I have the value.

pesterhazy15:09:17

await is syntactic sugar for .then

pesterhazy15:09:45

Hope that helps

awb9915:09:41

Cool! Thanks!

awb9915:09:13

Regarding Wrapping the whole thing into a promise.

awb9915:09:22

As the js/fetch uses callback,

awb9915:09:26

I thought this is my only option.

awb9915:09:07

I will watch your presentation!

benzap16:09:58

If you want to stay closer to clojure, you could wrap everything to use core.async. It can be a bit much starting out, but it can be well worth it.

benzap16:09:15

OH, he talks about core.async in that linked video

awb9916:09:14

@U0670BDCH I really just want to receive data, preprocess it, and then return it. And for each type of data this is a little different. So I thought this really just needs asynchronous funciton composition. As I understand the core.async it is more like communication, so not really suited for such simple issues. or am I wrong?

benzap16:09:44

Well, depending on what you do, once you go async, it becomes difficult to get out of async

benzap16:09:16

you could just write a blocking set of statements to do what you're doing, and it will likely be a bit slower. It would be more easily testable as well

benzap16:09:58

but once you go async, you are stuck doing either continuous callbacks, chaining together promises, or using core.async channels (to name a few)

benzap16:09:21

they all wrap the same core ideas. You have an event queue that you're plugging into

benzap16:09:12

when an event is done in callback based async, it's telling that callback that it's finished. Promises wrap around this concept and offload the callback as something you can define later

benzap16:09:34

core.async is different, in that you're now passing around channels, and you can choose how people get stuff out of that channel

benzap17:09:46

So you're right, it is just communication. However, some people would agree that you can do more idiomatic and functional things with a collection of data that is consumed from a stream

awb9921:09:01

@U0670BDCH I just realize that by passing channel names around it should also be possible to compose functions. I just need to get my brain adapted to such a pattern. Haha

pesterhazy15:09:18

second, the function returns a Promise (a JS object) but that's inevitable because it's an async computation

pesterhazy15:09:39

but what the promise resolves to will be a clojure data structure

lilactown16:09:07

how do I use cljs.core when using cljs.js/eval-str?

mfikes16:09:47

@lilactown cljs.core should be available unless :dump-core has been set to false (See https://clojurescript.org/guides/self-hosting)

lilactown16:09:16

turns out there’s a couple more steps with #shadow-cljs. I’m figuring it out. thanks 🙂