Fork me on GitHub
#re-frame
<
2018-10-15
>
TeMPOraL11:10:41

I have what is probably a very stupid question - how does a subscription know its value has changed?

TeMPOraL11:10:01

using random example from re-frame docs I have open, say I write:

(re-frame/reg-event-db
  :set-active-panel
  (fn [db [_ value]]
    (assoc db :active-panel value)))

(re-frame/reg-sub
  :active-panel
  (fn [db _]
    (:active-panel db)))

TeMPOraL11:10:46

when I then do a (re-frame/dispatch [:set-active-panel :panel1]), how does re-frame know that whatever is subscribing to :active-panel needs to be refreshed?

TeMPOraL11:10:49

right now I'm dealing with a situation like this: I have subscriptions A and B, and then a subscription C that uses A and B as input vectors, and just concatenates them) my component subscribes to C, and there are input fields that trigger calls which change (via an event-db dispatch) values that are listened to by A and B

TeMPOraL11:10:22

somehow, C does not catch the fact that values in DB are changed, and in trying to figure that out I realize I can't find any info on how do subscriptions actually know what's going on

TeMPOraL11:10:26

moreover, looking at the app state via re-frisk, I discovered that even A and B don't notice changes in the DB

mikethompson11:10:26

re-frame-10x is a tool which provides more information on when subscriptions are run and what values they create.

mikethompson11:10:31

You generally don't need to know how it works

mikethompson11:10:28

BTW, if the new value A tests = to the old value of A then no change is propogated

TeMPOraL11:10:16

I just fixed the problem, turns out it was PEBKAC (like usual), a mistake with qualified/unqualified keys

TeMPOraL11:10:25

careful looking at re-frisk window helped

TeMPOraL11:10:44

still, knowing how this works under the hood would help me keep some peace of mind 🙂

TeMPOraL11:10:03

for instance, I have some subscriptions I inherited in the codebase that look like (or (get-in app-db [:foo :bar]) (some-default-computed-value)), and yet they update themselves if the db state under :foo :bar changes

TeMPOraL11:10:21

does re-frame recompute all subscriptions at any db change?

TeMPOraL11:10:39

re-reading the flowchart now, thanks

mikethompson11:10:21

Also read the link at the bottom of that page, to the todomvc example. It is heavily commented.

TeMPOraL11:10:12

I think the answer to my question is actually on "The Signal Graph - a four layer tree" part of the flowchart, where there's a note that data flow stops when a subscription returns unchanged value

TeMPOraL11:10:32

I believe this resolves my confusion

mikethompson11:10:55

Righto. Keep re-frame-10x in mind too

👍 4
andrea.crotti17:10:24

related to this question (https://clojurians.slack.com/archives/C073DKH9P/p1539431269000200) which I maybe asked at the wrong time/day

andrea.crotti17:10:56

I got something vaguely working but I'm not sure it makes so much sense, and strangely I can't really find anything online about that

andrea.crotti17:10:38

anyone doing that who would like to share how they do oauth2 authentication in general? (Maybe it's more a SPA question more than a re-frame problem specifically)

andrea.crotti19:10:48

Sure that's not the problem really

andrea.crotti19:10:33

Just wondering what are the possible ways to do oath2 authentication in reframe

andrea.crotti19:10:29

The flow all works now, I have an endpoint that tells the frontend if the user is authenticated, and put that in the db

mikethompson21:10:17

oath2? Oh, sorry, your link seemed to take me to a discussion on a subscription topic.

mikethompson17:10:46

@temporal.pl you might also be interested ^^^ vvv