So, I created a QueryCursor now. But the Om component doesn't refresh yet when the cursor state changes. What am I missing?
; from https://gist.github.com/allgress/11348685 (defn bind ([conn q] (bind conn q (atom nil))) ([conn q state] (let [k (guid)] (reset! state (d/q q @conn)) (d/listen! conn k (fn [tx-report] (let [novelty (d/q q (:tx-data tx-report))] (when (not-empty novelty) ;; Only update if query results actually changed (reset! state (d/q q (:db-after tx-report))))))) (set! (.-__key state) k) state))) (deftype QueryCursor [conn q state] IDeref (-deref [_] state) om/ICursor (-path [_] []) (-state [_] state) om/ITransact (-transact! [_ _ _ _] (throw (js/Error. "not supported"))) IEquiv (-equiv [_ other] (if (om/cursor? other) (= state (-value other)) (= state other))) ISeqable (-seq [this] (when (pos? (count @state)) (map (fn [v _] (om/-derive this v state [])) @state (range)))) IPrintWithWriter (-pr-writer [_ writer opts] (-pr-writer q writer opts))) ; run a query (defn query [q] (QueryCursor. conn q (bind conn q))) Stephan On Monday, December 15, 2014 10:41:31 PM UTC+1, stephanos wrote: > Hey there, > > with my humble ClojureScript skills, I'm attempting to use Om and DataScript > together. But I struggle with closing the gap between a DataScript query and > an Om cursor. > > In my test app I have a DataScript query 'q-count' and an Om component > 'app-counter'. The main component looks like this: > > (defn app-view [] > (reify > om/IRender > (render [_] > (let [count (query q-count)] > (dom/div nil > (dom/h2 nil "Hello World") > (om/build #(app-counter count) {})))))) > > The 'query' function is supposed to run the query and, in order for the Om > component to automatically refresh upon change, return a cursor (it only > needs to be readable, not writeable). > > But how do I create a cursor from the query? I suppose Dave Dixon's Reagent > example can be applied here but I simply can't connect the dots. > > PS: The complete source code of the test app can be found at > https://github.com/stephanos/om-tutorial/blob/counter/src/todomvc/app.cljs > > Stephan -- 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.
