The two common types of errors I see in Om are the ITransact error that you
encountered and the IDeref one.

The former happens when you try to transact on something that isn't a
cursor. The two main reasons that I've seen where this happens are:

1. If you are trying to access a primitive:
(def (atom app-state {:foo "Foo"})

(defn bar [app owner]
  ...
    (om/update! app ...)

Then in the root component:
  (om/build bar (:foo app)

2. If you set part of a cursor to a sequence. This is what happened in your
case.

The key thing to remember is that only maps an vectors (by default, at
least) are turned into cursors! If you see the ITransact error, check what
you set the state to. This can be mystifying if the state is passed
directly from the server. You could protect against this by always calling
vec on data received from the server before placing it in the app state (if
its not a map, of course).

The IDeref happens when you pass a cursor to code that runs outside of the
Om render phase (or code that you thought runs outside render actually gets
called during render). Generally it means you forgot to deref/@ the cursor.

Another error that I've hit a few times (but seem to have internalized now)
is forgetting to use (apply dom/div nil (map ...)) instead of (dom/div nil
(map ...)).

One other error that had me stumped was something about being unable to
update an unmounted component. This was a tricky one to debug, but
basically what happened was I was calling om/update on owner inside a go
block that I set up in IWillMount, but the go block sticks around after the
component is unmounted (and gets duplicated when remounting!). The key
thing to remember is that if a component sets up go blocks in will-mount
and the component may get unmounted, you need to make sure to dispose of it
from IWillUnmount (eg by having a "kill" channel that the go block waits on
using alt/alts).

The error you've encountered is the only one that I've seen caused by
errors on the server, but as I said above, you could protect against this
in the client.


On 3 July 2014 19:18, Alex Huang <[email protected]> wrote:

> Hi everyone, beginner to cljs here.
>
> I just worked through the Intermediate Tutorial for Om at
> https://github.com/swannodette/om/wiki/Intermediate-Tutorial by following
> the explanations and typing along.
>
> The tutorial ends with editable input fields rendered by React and
> persisted in Datomic. At this point I encountered this error in the console
> (bug is in my code; keep reading):
>
> Uncaught Error: No protocol method ITransact.-transact! defined for type
> cljs.core/PersistentHashMap: {:class/id "6946", :db/id 17592186045423,
> :class/students #{{:db/id 17592186045428} {:db/id 17592186045430} {:db/id
> 17592186045431} {:db/id 175921...<omitted>...}} core.cljs:136
>
> So firstly the line doesn't match up. But I fiddle around with the "data"
> variable getting passed around in the "handle-change" function in core.cljs
> to no avail. I can cause another interface error which I'm not familiar
> with, and the line number doesn't change.
>
> Then I redid the entire tutorial and copy+pasted whenever possible, and
> realized that what causes this error is a missing "vec" argument in my
> (server-side!) core.clj:
>
> (defn get-classes [db]
>   (->> (d/q '[:find ?class
>               :where
>               [?class :class/id]]
>           db)
>        (map #(d/touch (d/entity db (first %))))
>        ;; BUG: when absent, leads to cljs error!
>        ;; vec
>        ))
>
> Totally didn't see that coming! My question is this. When you encounter an
> error like the one above, what clues tell you to look in the server-side
> clj rather than the client-side cljs?
>
> Thanks!
>
> --
> Note that posts from new members are moderated - please be patient with
> your first post.
> ---
> You received this message because you are subscribed to the Google Groups
> "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/clojurescript.
>

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to