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-20T00:01:01.224200Z

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

jimberlage 2020-04-20T14:02:59.224600Z

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 Farhad 2020-04-20T14:03:24.224800Z

Ahha ok

Shako Farhad 2020-04-20T14:03:53.225Z

I thought

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

Shako Farhad 2020-04-20T14:05:51.225200Z

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?

jimberlage 2020-04-20T14:16:40.225600Z

pr-str should be good.

Shako Farhad 2020-04-20T14:18:25.225800Z

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 Farhad 2020-04-20T14:19:05.226Z

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

(def ^:private async-storage AsyncStorage)

Shako Farhad 2020-04-20T14:19:56.226200Z

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

Shako Farhad 2020-04-20T18:19:07.226400Z

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? 😮

Shako Farhad 2020-04-20T20:54:15.227900Z

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?

jimberlage 2020-04-20T21:09:28.228500Z

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

Shako Farhad 2020-04-20T22:09:00.228900Z

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 😮

jimberlage 2020-04-20T22:18:01.229100Z

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

jimberlage 2020-04-20T22:18:22.229300Z

Downstream = in other parts of the code

Shako Farhad 2020-04-20T22:46:11.229500Z

Ah! I understand! Thanks for explaining! ^^

Shako Farhad 2020-04-21T10:08:09.244100Z

@jimberlage, 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 Farhad 2020-04-21T10:08:12.244300Z

?

Shako Farhad 2020-04-21T10:40:03.244500Z

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

Shako Farhad 2020-04-21T10:40:30.244700Z

Is it just wrapping it in try catch or?

Shako Farhad 2020-04-21T10:53:27.244900Z

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

Shako Farhad 2020-04-21T11:30:10.245100Z

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

Shako Farhad 2020-04-21T11:30:48.245400Z

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

jimberlage 2020-04-21T13:36:01.247300Z

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 Farhad 2020-04-21T13:37:33.247600Z

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 Farhad 2020-04-21T13:38:56.247800Z

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

Oliver George 2020-04-20T23:49:09.230400Z

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