Fork me on GitHub

@fasiha: Sure. What else do you want to know? No, not storing my connection inside the app-db. I never put anything but data in my app-db or datascript db so it can be serialized to disk or over the network. Why not just access the conn from outside the subscription?


@roberto: I found a much easier lifecycle library called mount. Doesn’t require a major re-architecture of the app and you get many of the benefits from component:

;; create the datascript database
(defstate shared-db
          :start (let [conn (init-ds-db! :shared-db config/shared-schema config/shared-storage-key)]
                   (d/listen! conn :shared-lunr-updates listen-update-lunr-index!)
          :stop (do (ds->async-storage @shared-db config/app-storage-key)
                    (d/unlisten! @shared-db :shared-lunr-updates)


I'm not a fan of mount. Used it in a project and I regret it. But if it works for you, rock on.


roberto, I'm curious what problems you had with mount


@seantempesta: nice, gotcha! I've used mount to handle backend services (nrepl, http-kit, DataScript on the backend), but never thought about using it in the front end. What namespace did you put that shared-db state in? In db.cljs?


While I was describing my stupid way of handling subscriptions into app-db to retrieve the Datascript conn, I realized I was doing it foolishly and reorganized it, but I can see that it's unwise to keep an atom to a Datascript db in app-db. Putting it in mount state sounds interesting enough to try


the things I don’t like about mount is that there is not an obvious way to know what are your dependencies. With component, there is one place you can get an overview of how the app is architected.


@fasiha: I made a separate datascript namespace


Some great re-frame discussion going on in this thread:


Hi all - I'm a beginner with both ClojureScript and re-frame - I've a (basic) question posted here - - any / all help much appreciated....


I’m curious as to why you are using make-reaction


...though even with clairvoyant and re-frame-tracer (which make things much clearer - brilliant) I'm still stumped!


are you sure that cv and votes are being populated?


i’m guessing that :current-vote is a map and not an :id


I'm fairly sure votes is populated but cv is not ... if I edit cvs-sub-reaction and replace (get-vote-by-id votes cv) with (get-vote-by-id votes 2) (for example) it's evaluating to a vector containing a single map, which is the desired result (except it's just always the one with the id I hard-code). :current-vote is a number which should match the :id of the map selected from :votes


I'm using :current-vote in my app-db as a reference to a specific item in :votes


yeah, which is why it is not giving you the answer


because cv is a map, not an integer


you want to extract the integer out of cv


(let [cv (get-in @db [:current-vote])
            votes (get-in @db [:votes])]
        (get-vote-by-id votes (:id cv)))


Thanks @roberto - but I'm not sure that's it (gave it a try though... appreciated). Above screenshot shows that get-vote-by-id is passed an integer, it's just that it's evaluating to []... but when I invoke get-vote-by-id directly (from repl) with same values, it works... utter confusion.


Just realised I contradicted my earlier comment - cv is evaluating to a number (sorry), and votes is an array.. it's the evaluation of get-vote-by-id that causes the confusion.