re-frame

https://github.com/Day8/re-frame/blob/master/docs/README.md https://github.com/Day8/re-frame/blob/master/docs/External-Resources.md
emccue 2021-01-08T00:51:56.202Z

@ps try doing this instead

emccue 2021-01-08T00:54:25.204400Z

(require '[re-frame.core :as rf])

(rf/reg-fx 
  ::get-from-async-storage
  (fn [{:keys [key when-retrieved]}]
    (-> (. AsyncStorage getItem key)
        (.then 
          (fn [value]
            (rf/dispatch (when-retrieved value)))))))
     

emccue 2021-01-08T00:54:52.205Z

Make an FX handler - this is the low level construct for defining how a side effect is performed

emccue 2021-01-08T00:55:11.205500Z

and give it a function to call when it is done that will return an event to dispatch with the new value

emccue 2021-01-08T00:55:25.205800Z

so then in your event handler

emccue 2021-01-08T00:57:24.207900Z

(rf/reg-event-fx
  :register-db
  (fn [db _]
    {:db db
     :fx [[::get-from-async-storage {:key "_id"
                                     :when-retrieved #(vector :got-value %)}]]}))

(rf/reg-event-db
  :got-value
  (fn [db [_ value]]
    (assoc db :value value)))

emccue 2021-01-08T00:57:44.208100Z

so you need two events

emccue 2021-01-08T00:58:03.208600Z

but there are (at least) two things happening that are not part of the model

emccue 2021-01-08T01:01:35.210200Z

try to have your fx handlers be few in number

emccue 2021-01-08T01:01:43.210500Z

and just write helpers on top of them

zendevil 2021-01-08T02:32:41.210600Z

thanks

emccue 2021-01-08T02:36:52.210800Z

(this is what the sample i gave below does, more or less)