Fork me on GitHub
#re-frame
<
2018-01-18
>
Miloslav16:01:14

Hi everyone!

Miloslav16:01:08

I have a problem with re-frame

Miloslav16:01:56

the data on certain db key is being updated correctly, but the subscription doesn't work

Miloslav16:01:57

(def state->pouch_sub (keyword (str pouchDatabaseName "-sub")))
  (re-frame/reg-sub
    state->pouch_sub
    (fn [db [_ _]]
      (.log js/console (clj->js db) "the whole db")
      ((keyword pouchDatabaseName) db)))

  (let [freshStateData (re-frame/subscribe [state->pouch_sub])]
    (.log js/console @freshStateData "subscription")))
Is it wrong?

Miloslav16:01:53

I used pretty much the same subscriptions elsewhere and it works just fine

jlfischer17:01:06

I need to double check when I'm back at my desk, but I'm fairly sure the db passed into your subscription function is a reagent atom; you need to dereference it within the sub function for it to realize when the app database changes.

Miloslav17:01:22

i'm dereferencing it right here (.log js/console @freshStateData "subscription")

Miloslav17:01:15

or should i deref it in sub function?

jlfischer17:01:18

Right, but that's within your component, not your subscription function.

Miloslav17:01:22

but my router is dereferences it like this

(defn main-panel []
  (let [active-panel (re-frame/subscribe [::active-panel])]
    [pages/panels @active-panel]))
and it works

Miloslav17:01:30

anyway thanks, I'll try this

jlfischer17:01:15

For a simple reference, this is one of the super basic subscriptions in one of my apps: (defn app-view "Which view the user is currently looking at." [db _] (reaction (:app/view @db)))

jlfischer17:01:30

So the whole thing is wrapped in (reaction ...) as well

Miloslav17:01:56

i just done that @db thing and it returned me that reaction

Miloslav17:01:14

i'm ahead to wrap it just like it in your code

jlfischer17:01:36

Looking closer, I use reg-sub-raw though, can't remember why.

Miloslav17:01:14

what is reaction?

Miloslav17:01:17

is it in re-frame ns?

Miloslav17:01:37

it seems like you just reimplemented the whole subscription thing

Miloslav17:01:54

wow, i haven't read this

Miloslav17:01:19

i somehow skipped that the first time when i'd read the docs

mikerod17:01:59

Yes, it is a good one

jlfischer17:01:58

Heh, the project I pulled that snippet from dates back to re-frame 0.2-ish. I think reg-sub back then worked like reg-sub-raw does now, so I just blindly renamed things while upgrading.

pcj17:01:48

this guy just realized double colon keywords are namespaced. going to rename all of my events and subs 😤