cljsrn

https://github.com/drapanjanas/re-natal | https://github.com/drapanjanas/re-natal/wiki/FAQ | https://github.com/condense/mercury-app/wiki | https://github.com/seantempesta/expo-cljs-template/ https://www.npmjs.com/package/create-expo-cljs-app
Shako Farhad 2020-04-19T13:30:40.194400Z

Anyone know a good way of integrating re-frame and the react native async storage? What are the dos and don'ts of using async storage and potential pitfalls? I am trying to get into and use it, but I don't know exactly where to start.

Shako Farhad 2020-04-19T13:32:49.195200Z

Is for example setting the whole re-frame app-db into async storage for every event not smart? Should only certain data be put in async storage?

dotemacs 2020-04-19T13:34:27.195500Z

This library can be useful to you: https://github.com/cljsrn/side-fx/blob/master/src/side_fx/storage.cljs

Shako Farhad 2020-04-19T17:22:16.196500Z

Guys how do I get AsyncStorage when it is imported without {} brackets?

import AsyncStorage from '@react-native-community/async-storage';

Shako Farhad 2020-04-19T17:22:58.196900Z

For react native it is like this:

["react-native" :refer [ActivityIndicator]]

Shako Farhad 2020-04-19T17:23:59.197700Z

But that is also written like this:

import { ActivityIndicator } from 'react-native';

joshmiller 2020-04-19T19:37:49.199200Z

@shakof91 I worried about storing my whole app-db on every event but for my use case it’s imperceptible. I’d start by just doing that, the simplest thing that works, and then if you end up noticing issues later, find a solution.

Shako Farhad 2020-04-19T19:39:41.200800Z

I was thinking of just storing the whole app-db everytime the app-state changes to "background", but perhaps storing the whole app-db on every event is better since then we won't have any edgecases (like if app gets forced shutdown and not going into "background" first).

Shako Farhad 2020-04-19T19:40:23.201600Z

But do you know how to get the AsyncStorage from the community version of the async-storage? Currently this works for me

["react-native" :refer [AsyncStorage]]

joshmiller 2020-04-19T19:41:18.202400Z

Yeah, I did that originally, but I found that it wasn’t entirely reliable and I had to be more careful about syncing things. It turns out that just adding a side-effect that stores the app-db on every event is dumb and just works.

joshmiller 2020-04-19T19:42:29.203300Z

I’m not using shadow-cljs in my project (or the newer CLJS NPM stuff). So it’s a little different. Honestly I get confused by the differences in ES6/etc export styles. I have a lot of this:

joshmiller 2020-04-19T19:42:50.203900Z

(.-ActivityIndicator (js/require "react-native"))

Shako Farhad 2020-04-19T19:43:22.204900Z

Ok. Thank you for the headsup. I will definitely see if I can do the save on every event. How did you solve that by the way?

joshmiller 2020-04-19T19:43:39.205300Z

You can mess around in the repl by doing (def rn (js/require "react-native")) and then (js-keys rn) or whatever to see what’s in there.

joshmiller 2020-04-19T19:44:07.205900Z

I have a blog post about saving on every event here: https://increasinglyfunctional.com/2018/10/31/app-group-data-sync-with-clojurescript-and-re-frame.html

Shako Farhad 2020-04-19T19:44:10.206100Z

ah really. Didn't know that! Will try that. Thanks!

joshmiller 2020-04-19T19:44:50.207Z

What I’m doing is a little more complicated because I’m not using AsyncStorage, but if you scroll down, you can see how to plug into re-frame and just put your storage code there.

Shako Farhad 2020-04-19T19:45:57.208Z

Ah so you are using the (after) function. So after the event has gone through all its coeffects, you put the current db in storage. neat!

joshmiller 2020-04-19T19:46:40.209400Z

Yup, it turns out to work just fine for storing a few kb at least.

Shako Farhad 2020-04-19T19:47:48.210400Z

When I do "yarn add @react-native-community/async-storage", does this mean I need to get async-storage from @react-native-community/async-storage or is the react-native async-storage automagically overwritten and points to the community version? 😛

Shako Farhad 2020-04-19T19:48:15.210900Z

I have kept to the core react-native stuff. This is my first package outside of react-native and react 😄

Shako Farhad 2020-04-19T19:48:30.211400Z

I bet I will have to figure this out soon either way.

joshmiller 2020-04-19T19:49:19.212400Z

I don’t think adding something with yarn automatically pulls it in. You do that when you either require in your ns form or if you js/require. Whatever you require and define is what you get.

Shako Farhad 2020-04-19T19:52:25.213600Z

Yes. I was just wondering if

["react-native" :refer [AsyncStorage]]
["@react-native-community/async-storage" :refer [AsyncStorage]]
are the same kind of because of react natives auto linking from 0.60 and up. 😮

Shako Farhad 2020-04-19T19:53:41.214100Z

So much I still don't quite understand. But this whole react native journey has been mostly pleasant actually. 😄

joshmiller 2020-04-19T19:54:54.214800Z

Ah, I see. I’m honestly not sure either, the RN packager does some magic and I’m sometimes surprised by what happens.

dotemacs 2020-04-19T20:00:37.217500Z

They are not the same thing @shakof91 because I think that AsyncStorage got pulled out of react-native.

dotemacs 2020-04-19T20:01:07.218Z

The first line used to work, but the second require is what you need nowdays…

Shako Farhad 2020-04-19T20:02:05.219Z

Unfortunatly

["@react-native-community/async-storage" :refer [AsyncStorage]]
gives me an error. It says that AsyncStorage is not an object and that type is undefined. I saw others online have the same issue. I just need to figure out how to require it correctly 😮

Shako Farhad 2020-04-19T21:04:50.220600Z

I found the answer!

Shako Farhad 2020-04-19T21:05:59.220700Z

This is from the shadow-cljs documentation. So in my case I needed to use this

["@react-native-community/async-storage" :default AsyncStorage]

👍 1
Shako Farhad 2020-04-19T23:25:03.222100Z

The async-storage doesn't seem to work. Whenever I quit the app and relaunch it, the async-storage is empty again. :x