Fork me on GitHub
#re-frame
<
2016-06-10
>
seantempesta01:06:29

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

seantempesta01:06:17

@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!)
                   conn)
          :stop (do (ds->async-storage @shared-db config/app-storage-key)
                    (d/unlisten! @shared-db :shared-lunr-updates)
                    nil))
https://github.com/tolitius/mount/

roberto01:06:09

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

escherize01:06:26

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

fasiha01:06:33

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

fasiha01:06:40

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

roberto02:06:37

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.

seantempesta03:06:49

@fasiha: I made a separate datascript namespace

escherize11:06:56

Some great re-frame discussion going on in this thread: https://github.com/Day8/re-frame/issues/170

pauldelany14:06:05

Hi all - I'm a beginner with both ClojureScript and re-frame - I've a (basic) question posted here - http://stackoverflow.com/questions/37751108/re-frame-subscription-not-working-as-expected - any / all help much appreciated....

roberto15:06:18

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

pauldelany15:06:19

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

roberto15:06:04

are you sure that cv and votes are being populated?

roberto15:06:02

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

pauldelany16:06:29

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

pauldelany16:06:49

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

roberto16:06:35

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

roberto16:06:47

because cv is a map, not an integer

roberto16:06:55

you want to extract the integer out of cv

roberto16:06:21

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

pauldelany16:06:10

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.

pauldelany17:06:11

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.