zendevil 2021-01-07T04:57:38.172700Z

I’m getting the following error inexplicably. What does this error mean?

zendevil 2021-01-07T04:57:49.173Z

re-frame: no :event handler registered for: {"__hash": null, "arr": [{"_hash": null, "cljs$lang$protocol_mask$partition0$": 2153775105, "cljs$lang$protocol_mask$partition1$": 4096, "fqn": "_id", "name": "_id", "ns": null}, "5ff6924434880e93f086fc14"], "cljs$lang$protocol_mask$partition0$": 16647951, "cljs$lang$protocol_mask$partition1$": 139268, "cnt": 1, "meta": null}


That means you are dispatch-ing a vector where that map is the first element


Ie. it is as if your are doing:

(dispatch [{"__hash": null, "arr": [{"_hash": null, "cljs$lang$protocol_mask$partition0$": 2153775105, "cljs$lang$protocol_mask$partition1$": 4096, "fqn": "_id", "name": "_id", "ns": null}, "5ff6924434880e93f086fc14"], "cljs$lang$protocol_mask$partition0$": 16647951, "cljs$lang$protocol_mask$partition1$": 139268, "cnt": 1, "meta": null}])

zendevil 2021-01-07T05:00:09.175300Z

Here’s my handler

zendevil 2021-01-07T05:00:10.175600Z

 (fn [coeffects [_ google-id]]
   (js/console.log "google id is!" google-id)
    (assoc (:db coeffects) :signed-in true)
    (http-get "/api/sign-in"
               {:google-id google-id}
               #_(fn [] (js/console.log "success"))
               #_(fn [] (js/console.log "failure")))}



re-frame is extracting the first element of the event vector ... which is that map ... and then trying to find an event handler which is registered for it


@ps the issue is with the dispatch

zendevil 2021-01-07T05:01:06.176500Z

how to fix it?


Q: do you understand the problem I described?

zendevil 2021-01-07T05:01:36.177300Z

i’m only dispatching things that are handlers


Clearly not


As I said, you are dispatching a complicated map


(Or at least that seems to me what it happening)

zendevil 2021-01-07T05:02:24.178600Z

where am i dispatching it?

zendevil 2021-01-07T05:02:56.179100Z

(defn http-get [uri params on-success on-failure]
  {:method :get
   :uri (str "<http://localhost:3000>" uri)
   :params params
   :on-success on-success
   :on-failure on-failure
   :response-format (edn/edn-response-format)
   :format (edn/edn-request-format)

zendevil 2021-01-07T05:03:22.179400Z

 (fn [coeffects [_ response]]
  (js/console.log "response is" response)

zendevil 2021-01-07T05:03:31.179800Z

and the console log in set-id isn’t getting printed

zendevil 2021-01-07T05:05:45.180400Z

how to fix this?


Perhaps the on-success and on-failure vectors are wrong

zendevil 2021-01-07T05:09:20.182Z

why are they wrong?


(defn http-get [uri params on-success on-failure]
  {:method :get
   :uri (str "<http://localhost:3000>" uri)
   :params params
   :on-success on-success
   :on-failure on-failure
   :response-format (edn/edn-response-format)
   :format (edn/edn-request-format)


Because they should be vectors which are dispatchable

zendevil 2021-01-07T05:09:48.183100Z

but they are vectors

zendevil 2021-01-07T05:10:12.183500Z

(http-get "/api/sign-in"
               {:google-id google-id}
               #_(fn [] (js/console.log "success"))
               #_(fn [] (js/console.log "failure")))

zendevil 2021-01-07T05:10:24.183800Z

[:set-id] is the onsuccess vector

zendevil 2021-01-07T05:12:27.185700Z

now it works

zendevil 2021-01-07T05:12:30.185900Z

i don’t know how

p-himik 2021-01-07T08:38:23.189900Z

@mikethompson I don't think you were entirely correct. That "complicated map" is just how a keyword within a 1-entry map is printed out by a pure text JS console:

cljs.user=&gt; (js/console.log {:x 1})
  meta: null,
  cnt: 1,
  arr: [
      ns: null,
      name: 'x',
      fqn: 'x',
      _hash: 2099068185,
      'cljs$lang$protocol_mask$partition0$': 2153775105,
      'cljs$lang$protocol_mask$partition1$': 4096
  __hash: null,
  'cljs$lang$protocol_mask$partition0$': 16647951,
  'cljs$lang$protocol_mask$partition1$': 139268
Although, I have no idea how to get that exact message in a browser's console - at least Chrome and Firefox wrap it in an interactive object that looks a bit differently. But of course, something was not right in the original code/state of the app in the first place.

p-himik 2021-01-07T08:51:12.192700Z

@ps I'm pretty sure I know what happened. 1. You set :on-failure to [] and make the request to /api/sign-in 2. The request to fails 3. The body of the failure response is parsed and conj-ed into that empty vector (seems like that body contained a map {:_id "5ff6924434880e93f086fc14"}) 4. That vector then passed to dispatch In short, don't use empty vectors when specifying :on-success and :on-failure. Specify nil instead.


@p-himik Makes perfect sense!! Good sleuthing.

zendevil 2021-01-07T10:07:43.194300Z

I’m trying to persist the app state

zendevil 2021-01-07T10:07:43.194400Z

using re-frame-storage

zendevil 2021-01-07T10:07:43.194500Z

and I’m using the following:

zendevil 2021-01-07T10:07:44.194600Z

(reg-co-fx! :my-app         ;; local storage key
          {:fx :store     ;; re-frame fx ID
             :cofx :store}) ;; re-frame cofx ID

zendevil 2021-01-07T10:07:44.194700Z

but this gives the error that the app isn’t registered

zendevil 2021-01-07T10:07:44.194800Z

how to fix this error?


@p-himik I don't think that :on-failure nil would work. Best to just not include the key :on-failure (rather than to have it with a value of nil)

zendevil 2021-01-07T10:10:37.196100Z

zendevil 2021-01-07T10:10:55.196600Z

when I remove the snippet the error is gone

zendevil 2021-01-07T10:11:17.197Z

yet that’s exactly copied from the github readme of re-frame-storage

zendevil 2021-01-07T10:26:21.197600Z

i get the same error as well when using the following:

(defn my-reg-event-db
  [event-id handler]
    [(persist-db :my-app :persistent)]
    (fn [{:keys [db]} event-vec]
      {:db (handler db event-vec)})))

;; ...

  (fn [db _]
    (print (get-in db [:persistent :foo]))
    (assoc-in db [:persistent :bar] "qux")))

zendevil 2021-01-07T10:26:26.197800Z

How to fix these errors?

p-himik 2021-01-07T10:56:31.198Z

I don't think the error has anything to do with re-frame.

p-himik 2021-01-07T10:58:08.198200Z

Although if the "A module failed to load due to an error" clause is what's happening, then it can be related to re-frame. But there's no way to figure it out without the underlying error.

p-himik 2021-01-07T10:58:38.198400Z

Try wrapping new code in try-catch and log the error.

zendevil 2021-01-07T12:21:41.199200Z

I’ve successfully stored a value with AsyncStorage, but I want to get the value and use the value. But I can’t pass the value because the function returns a promise, which must be wrapped in a go block

zendevil 2021-01-07T12:22:10.199400Z

 (fn [db [_ params]]
     (prn "sync storage is "
          (&lt;p! (. AsyncStorage getItem "_id"))))

zendevil 2021-01-07T12:22:34.200100Z

I want to take the value in AsyncStrorage getItem and assoc it with the app-db map.

zendevil 2021-01-07T12:22:38.200300Z

How to do that?

zendevil 2021-01-07T12:25:30.201Z

is there a workaround for putting this value in the db?

p-himik 2021-01-07T12:27:54.201200Z

Use reg-event-fx instead, create another event and dispatch it from the promise's resolve callback. Ideally, wrap it all up in an effect to keep that event handler pure.