Fork me on GitHub
#cljsrn
<
2020-07-06
>
benny17:07:19

has anyone used re-frame & async storage with rn? i’m having issues writing a coeffect that can read from storage and it’s proving to be tricky in cljs

ferossgp06:07:04

I use an effect with callback event. Pseudo implementation:

(defn get-items
  [db-keys cb]
  (-> async-storage
      (.multiGet (clj->js (mapv keyword->string db-keys)))
      (.then process-data)
      (.then cb)
      (.catch (fn [error]
                       (cb nil)
                       (log/error "[async-storage]" error)))))

(reg-fx
 :data-store/get
 (fn [{:keys [keys cb]}]
   (get-items keys #(dispatch (conj cb %)))))
And use like that:
:data-store/get {:keys [:user/token]
                     :cb   [::auth/init]}

ferossgp06:07:19

process-data
In my case is transit so I do some transformations there.