You have not implemented ICursor. Just implementing IToCursor is not enough.
On Sun, Jan 25, 2015 at 9:45 AM, stephanos <[email protected]> wrote: > First of all, thanks for taking the time to reply. > > Okay, maybe DatabaseCursor is the wrong name, DatabaseWrapper then. > > When I use this > > ;; prevent cursor-ification > (extend-type d/DB > om/IToCursor > (-to-cursor > ([this _] this) > ([this _ _] this))) > > it's preventing Om to turn d/DB into some kind of cursor. But when a > change is made to the database, Om re-renders the view. How does it figure > that out? > > When I pass my custom DatabaseWrapper, which implements IAssociative and > ILookup as well as om/IToCursor - it is not re-rendered anymore (I couldn't > extend d/DB directly, it caused DataScript internal issues). I also tried > implementing ICursor instead of IToCursor, but none of the methods were > ever called. > > So how can I have a wrapper of a DataScript database that supports > IAssociative and still make Om re-render after any change to it? What's > missing? > > Stephan > > > On Sunday, January 25, 2015 at 3:29:33 PM UTC+1, David Nolen wrote: > > This won't be considered a cursor since it does not implement ICursor. > > > > > > David > > > > > > On Sun, Jan 25, 2015 at 5:09 AM, stephanos <[email protected]> wrote: > > Hey there, > > > > > > > > I'm trying to integrate Om and DataScript. > > > > > > > > At first I used David Nolen's gist [1] that implements 'om/IToCursor' > for DataScript's DB type. That worked out well for some time. But now I try > to apply Om's experimental support for writing all local state into the app > state [2]. This requires an associative data structure because of its use > of 'assoc' and 'get-in'. > > > > > > > > So I attempted to write a wrapper around the DataScript DB atom, > DatabaseCursor. Now, while I succeeded in saving the local state to it by > implementing IAssociative and ILookup, the app does not re-render on change > anymore :( > > > > > > > > I originally assumed all I needed was to implement the IEquiv or IHash > protocol, but that does not seem to work (both are never called). So I'm > stuck right now. Here is my DatabaseCursor: > > > > > > > > (deftype DatabaseCursor [conn] > > > > ILookup > > > > (-lookup [this k] > > > > (-lookup this k nil)) > > > > (-lookup [_ k not-found] > > > > (let [v (ffirst (d/q '[:find ?v :in $ ?k :where [?e :key ?k] [?e > :value ?v]] @conn k))] > > > > (or v not-found))) > > > > IAssociative > > > > (-contains-key? [_ k] > > > > (not (empty? (d/q '[:find ?e :in $ ?k :where [?e :key ?k]] @conn > k)))) > > > > (-assoc [this k v] > > > > (let [old-id (ffirst (d/q '[:find ?e :in $ ?k :where [?e :key ?k]] > @conn k)) > > > > new-id (if old-id {:db/id old-id} {})] > > > > (d/transact! conn [(merge new-id {:key k, :value v})])) > > > > this) > > > > om/IToCursor > > > > (-to-cursor [this _] this) > > > > (-to-cursor [this _ _] this)) > > > > > > > > How to I need to modify my custom cursor to make Om aware of changes to > the DataScript DB? > > > > > > > > [1] https://gist.github.com/swannodette/11308901 > > > > [2] > https://github.com/swannodette/om/commit/ee9d92bf1191a391df804c066868c8180f9d64cf > > > > > > > > -- > > > > 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. > -- 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.
