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.