Fork me on GitHub
#cljsrn
<
2020-04-20
>
Shako Farhad00:04:01

How does your keys look in setItem and getItem? Are they normal clojure keys? :x

jimberlage14:04:59

You'll want to use regular strings as keys. Your keywords are likely getting coerced to something like [Object object] and everything comparing the same.

Shako Farhad14:04:53

I thought

(pr-str key)
would make clj keys into strings 😮

Shako Farhad14:04:51

This is what I use. So I thought even if I send in :saved-db it would be made into ":saved-db" string and it would work. Have you implemented this differently?

jimberlage14:04:40

pr-str should be good.

Shako Farhad14:04:25

The weird thing is that my functions are not getting errors or anything. They are running successfully and it seems like things are getting extracted correctly from the storage while the app is running. But when the app shutsdown and I start it up again, the same keys return empty. 😮

Shako Farhad14:04:05

(ns reagent-app-project.db
  (:require ["@react-native-community/async-storage" :default AsyncStorage]
            [cljs.reader :refer [read-string]]))

(def ^:private async-storage AsyncStorage)

Shako Farhad14:04:56

I am also using (read-string result) to make it into clojure map from string 😮

Shako Farhad18:04:07

Is the problem perhaps how I am getting the async-storage on startup? How do you connect back to the same async storage on startup of app? 😮

jimberlage19:04:35

Here's what I have in my app right now - seems to be working. It's accessed globally, like (async-storage/get-edn :token). I know the library works best as a global storage, and the key it uses internally is your app identifier, so al long as your app identifier stays them same across restarts you should be good. Wiping the sim will wipe AsyncStorage as well

Shako Farhad20:04:15

Hmmm.. I see. I will try to make changes on my end see if it works then. Thank you so much! 🙂 You are ignoring the errors from the methods I see. Is this for performance reasons or just not interesting and usually it works flawlessly?

jimberlage21:04:28

I don't ignore them, but they're handled downstream. AsyncStorage is pretty reliable though

Shako Farhad22:04:00

What does it mean to handle them downstream? I am a scientist more than a programmer so there are things I am not familiar with 😮

jimberlage22:04:01

I handle errors differently each time I call async-storage/get-edn - since it's a promise, I handle errors in a callback depending on what is appropriate to do for that specific failure. If that makes sense

jimberlage22:04:22

Downstream = in other parts of the code

Shako Farhad22:04:11

Ah! I understand! Thanks for explaining! ^^

Shako Farhad10:04:09

@U4QC052UQ, are you doing something like this in your init function:

(rf/dispatch-sync [:initialize-db (if-let [storage (get-edn :saved-db)]
                                    storage
                                    default-db)])

Shako Farhad10:04:03

I am not quite sure how to work with promise objects :x

Shako Farhad10:04:30

Is it just wrapping it in try catch or?

Shako Farhad10:04:27

I really don't understand how to deref #object[Promise [object Object]]. :x

Shako Farhad11:04:10

I found the problem! It could not read React Native Animation object.

Shako Farhad11:04:48

Got to figure out how to add such an object to the edn reader. :x

jimberlage13:04:01

That's a tricky one. JS objects are tough to print well. To tell you the truth, I don't use re-frame anymore, I just know how to use it from past experience. Your call to get-edn looks OK, but you probably need to have it be an effect since it's not going to return immediately

Shako Farhad13:04:33

I don't know if this is the best way of doing it, but what I am doing is that I am loading the app-db, then I am sending it into a function that sets all the animation values to the value they should be, then the app starts up. What do you guys think? Is this a good way of doing it? I am basically saving the actual values in the DB and letting the animated value objects be (r/atoms).

(defn init-animations [db]
  (let [current-opacity (get-in db [:animation :bottom-modal-bg-fade :opacity])]
    (animation/set-value @bottom-fade-val current-opacity)
    db))

Shako Farhad13:04:56

So everytime a animation is fired, I am saving the value of that animation in the db (fade-to 1) saving 1 but leaving the actual object be some global variable. Hmm ;x

jimberlage19:04:35

Here's what I have in my app right now - seems to be working. It's accessed globally, like (async-storage/get-edn :token). I know the library works best as a global storage, and the key it uses internally is your app identifier, so al long as your app identifier stays them same across restarts you should be good. Wiping the sim will wipe AsyncStorage as well

Oliver George23:04:09

@dnolen I think you want Krell feedback in this channel. Perhaps good to update the Reagent Tutorial which links to #cljs-dev