Fork me on GitHub
#reagent
<
2018-08-23
>
jsa-aerial00:08:33

Hmmmm, maybe 'cursors' is the typical/standard means for addressing this?

mikerod00:08:55

@jsa-aerial yeah that’s not always true. You can have cursors and other sorts of reactions that derive from some subset of the single ratom state. These constructs can intelligent avoid re-notifying watchers, eg re-rendering, when the change doesn’t result in a difference derived value.

jsa-aerial13:08:03

@mikerod I see - sort of - what are these 'intelligent constructs'? Another idea I had is to have ratoms in the main ratom to differentiate these things. Since changes to these 'sub' ratoms would not change the value of the containing ratom, that might be a workable solution.

mikerod14:08:40

@jsa-aerial There are other constructs beyond the ratom

mikerod14:08:07

those can derive from data based on a ratom and there are built-in checks they perform to ensure that what they depend on has indeed changed

mikerod14:08:31

like a rcursor will only depend on a value at a path in the ratom (or reactive thing it depends on)

mikerod14:08:11

and if the value at that path hasn’t changed, then the watchers (eg would be component renderers) of the cursor won’t be updated

mikerod14:08:40

In the case of ratom’s, if the value at the path is identical? watchers aren’t notified

jsa-aerial14:08:10

That, seems to no longer be true from reagent 0.6+ it appears to use = for change in ratoms

mikerod14:08:02

similarly for reactions

mikerod14:08:42

sorry, reactions have 2 sides, the incoming data is compared via identical? I think, the outgoing result is using = https://github.com/reagent-project/reagent/blob/v0.8.1/src/reagent/ratom.cljs#L418 this is what I think you are referencing from the 0.6 changelog

jsa-aerial14:08:30

yeah - that must be the 0.6 change I had seen.

mikerod14:08:46

identical? is the test most often used

jsa-aerial14:08:50

Right - but do these (other than 'cursors') exist in reagent or some lib or are these typically hand rolled?

mikerod14:08:05

there are others

mikerod14:08:13

ns reagent.ratom defines several

mikerod14:08:23

for different sort of usage-scenarios

mikerod14:08:07

if you scroll towards bottom, you’ll see things like track! and reaction

jsa-aerial14:08:41

Ah... I will look at that - only in the code?

jsa-aerial14:08:10

That, seems to no longer be true from reagent 0.6+ it appears to use = for change in ratoms

jsa-aerial14:08:59

Not that that makes a difference in this context...

jsa-aerial14:08:41

Ah... I will look at that - only in the code?

jsa-aerial14:08:05

I thought I read all of that but I may have stopped after cursors. :thinking_face:

😄 4
mikerod14:08:21

I’m a fan of re-frame nowadays. The default there is for a single ratom to hold all of the app state

mikerod14:08:35

re-frame uses reactions to based derived views on the single app state data. Re-renders are avoided due to this change detection built into the reactions

mikerod14:08:43

regardless of if you want to use re-frame or not, there are a few good docs there about this topic. This section stands out https://github.com/Day8/re-frame/blob/master/docs/SubscriptionFlow.md#how-flow-happens-in-reagent

jsa-aerial14:08:01

I see - was thinking of looking into re-frame as a mid-term thing, but maybe need to bring that forward. All that reaction stuff (with the numerous protocols) is rather low level and complicated. Nice to build something with - apparently like re-frame....

mikerod14:08:35

I like reagent and created a large-ish app before with it alone

mikerod14:08:17

over time I started buying into the re-frame ideas more and more and I switched to it for future app’s and also uplifted the larger reagent one I had. One main reason is I like the better prescribed structure and “life cycle” of re-frame

mikerod14:08:02

reagent alone, to me at least, is more of a “do it yourself”.I still think you’ll wind up creating some sort of “framework/architecture” around the reagent constructs anyways - so it just comes down to if you like re-frames model or not

jsa-aerial14:08:37

@mikerod Thanks for this - appreciated!

👍 4
justinlee16:08:55

@jsa-aerial I totally agree with what @mikerod says above. For me, I just follow a fairly simple and rigid practice of “subscribing” to the data I need in the main ratom by creating cursors in a let-block to the specific paths I need for any given component. this keeps its rerender minimal and has the side benefit of making it easy to see what data a component depends upon. I think re-frame does this or something similar with its subscription mechanism.

👍 4
✔️ 4
dijonkitchen18:08:22

Thanks for the insight everyone! I think what I missed was the rerendering. We might explore cursors to make it more specific, so non-reframe-subscribed field components can still “work” when you type text.