Okay, I think have figured it out.

In the version where I pass the DataScript database to Om it actually passes it 
inside an atom. That very atom is modified when calling d/transact! and Om has 
registered listeners via add-watch to trigger a check for re-rendering.

My custom wrapper is not an atom, so Om wraps it in one. But obviously when 
changes to the wrapper's inner atom are made, the outer atom does not know 
about it. The check for re-rendering is never triggered.

So, I suppose the wrapper needs to somehow forward the methods of an atom to 
the inner atom.

Stephan

On Sunday, January 25, 2015 at 4:10:39 PM UTC+1, stephanos wrote:
> Thanks David, I'll spend more time with the source code and the debugger. And 
> report back.
> 
> Stephan
> 
> On Sunday, January 25, 2015 at 4:07:26 PM UTC+1, David Nolen wrote:
> > Om does not require cursors to render anything. This has been the case for 
> > quite some time. Re-rendering is triggered by the following series of 
> > conditionals:
> > 
> > 
> > https://github.com/swannodette/om/blob/master/src/om/core.cljs#L309
> > 
> > 
> > The first one works for any values, it's just an equality check.
> > 
> > 
> > I don't really have much to suggest other than if you're going to go down 
> > this path you going to have to familiarize yourself with the Om source code 
> > by reading it and debugging your cursor implementation through source 
> > mapping and stepping through Om execution.
> > 
> > 
> > 
> > David
> > 
> > 
> > On Sun, Jan 25, 2015 at 9:56 AM, stephanos <[email protected]> wrote:
> > Sorry, I'm not getting it. This
> > 
> > 
> > 
> >     ;; prevent cursor-ification
> > 
> >    (extend-type d/DB
> > 
> >      om/IToCursor
> > 
> >      (-to-cursor
> > 
> >        ([this _] this)
> > 
> >        ([this _ _] this)))
> > 
> > 
> > 
> > does also not implement ICursor, but it works (ie re-renders) anyway. What 
> > makes Om re-render the view after I call d/transact! on the database that I 
> > pass in as the root state?
> > 
> > 
> > 
> > Stephan
> > 
> > 
> > 
> > On Sunday, January 25, 2015 at 3:51:55 PM UTC+1, David Nolen wrote:
> > 
> > > 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.

-- 
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