Fork me on GitHub
#re-frame
<
2018-10-25
>
danielstockton12:10:19

How do re-frame subscriptions work under the hood?

danielstockton12:10:34

How does a subscription know that a part of the app-state it is concerned with has changed?

danielstockton13:10:15

Does it just run all subscriptions and see if the value changed? If so, it's up to me to properly combine extractors and computations to improve the efficiency..

Braden Shepherdson13:10:57

computers are fast. worry about it when it becomes a problem.

Braden Shepherdson13:10:41

it's still, quite literally, orders of magnitude more efficient than AngularJS, which re-runs every binding every time, and does so repeatedly until nothing changes anymore.

👍 4
isak13:10:15

@danielstockton i work around this problem by just using reg-sub-raw and cursors when appropriate

isak13:10:49

that default behavior has always seemed crazy to me, though i'm sure it works fine for most people

danielstockton13:10:40

I'm coming from om.next where the re-reads are more explicit, or are inferred from component queries.

danielstockton13:10:09

I'm sure it isn't a problem if you design your app-db right, and use more layer3 subs.

Braden Shepherdson13:10:48

that seems to be the broad advice. have simple, fast L2 subs to pull out slices of the app-db you care about, and then put everything else into L3. components at the bottom should depend directly on L3 subscriptions without further editing or filtering, so that they only run when they need to.

Braden Shepherdson13:10:04

manipulating the DOM is many times more expensive than running a few pure CLJS functions.

danielstockton13:10:00

Yes, i just had the realization why this is best practice. I was using far too many layer2 subscriptions probably.

danielstockton13:10:24

I can imagine it's a common newbie mistake

frenata13:10:19

I've been playing with different kinds of subscription generators -- the next direction I'm hoping to explore is specing out a nested map and generating a tree of subscriptions from that spec.